玄关求助
查看原帖
玄关求助
744853
FChang楼主2024/9/27 19:16
#include <bits/stdc++.h>
#define endl() putchar('\n')
#define space() putchar(' ')
using namespace std;
const int N = 1e5 + 5;

int n, m;

int a[N];

map <pair<__int128,__int128> ,bool> mp;

inline int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while(!isdigit(ch)) {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    return x * f;
}

void write(__int128 x) {
    if(x < 0) putchar('-'), x = -x;
    if(x > 9) write(x / 10);
    return void(putchar(x % 10 + 48));
}

signed main() {
    n = read();
    __int128 t[2];
    string ans = "No two snowflakes are alike.";
    while(n--) {
        for(register int i = 1; i <= 6; ++i) a[i] = read();
        for(register int i = 1; i <= 6; ++i) {
            t[0] = t[1] = 0;
            int cnt = 0, flag = 0;
            for(register int j = i; j <= 6; ++j, t[flag]*=10) {
                if(cnt > 3) flag = 1;
                t[flag] = t[flag] * 100000000 + a[j];
                ++cnt;
            }
            for(register int j = 1; j < i; ++j, t[flag]*=10) {
                if(cnt > 3) flag = 1;
                t[flag] = t[flag] * 100000000 + a[j];
                ++cnt;
            }
            if(mp[{t[0], t[1]}]) ans = "Twin snowflakes found.";
            mp[{t[0], t[1]}] = 1;
        }
        for(register int i = 1; i <= 6; ++i) {
            t[0] = t[1] = 0;
            int cnt = 0, flag = 0;
            for(register int j = i - 1; j >= 1; --j, t[flag]*=10) {
                if(cnt > 3) flag = 1;
                t[flag] = t[flag] * 100000000 + a[j];
                ++cnt;
            }
            for(register int j = 6; j >= i; --j, t[flag]*=10) {
                if(cnt > 3) flag = 1;
                t[flag] = t[flag] * 100000000 + a[j];
                ++cnt;
            }
            if(mp[{t[0], t[1]}]) ans = "Twin snowflakes found.";
            mp[{t[0], t[1]}] = 1;
        }
        if(ans != "No two snowflakes are alike.") break;
    }
    cout<<ans<<"\n";
    return void(endl()), signed(0);
}

本人吧序列暴力拼成两个int128然后用map存储,95pts,求卡厂

2024/9/27 19:16
加载中...