結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー Carpenters-Cat
提出日時 2022-10-15 00:13:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 987 ms / 3,000 ms
コード長 1,642 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 203,336 KB
最終ジャッジ日時 2025-02-08 05:19:31
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 70
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
ull const h = (1ull << 61) - 1;
ull b;
ull Bs[1000010];
ull mpl(ull x, ull b) {
    ull ret = 0;
    while (b) {
        if (b & 1) {
            ret += x;
            ret = (ret >= h ? ret - h : ret);
        }
        x <<= 1;
        x = (x >= h ? x - h : x);
        b >>= 1;
    }
    return ret;
}
int main () {
    int N;
    cin >> N;
    random_device dev;
    mt19937 mm(dev());
    uniform_int_distribution<ull> rd(998244353, (ull)1e15);
    b = rd(mm);
    Bs[0] = 1;
    for (int i = 1; i < 1000010; i ++) {
        Bs[i] = mpl(Bs[i - 1], b);
    }
    unordered_set<ull> st;
    ull hss[1000010];
    for (int i = 0; i < N; i ++) {
        string s;
        cin >> s;
        bool ok = false;
        ull hs = 0;
        int n = s.size();
        for (int i = 0; i < n; i ++) {
            hss[i] = mpl(s[i] + 100, Bs[n-i]);
            hs += hss[i];
            hs = (hs >= h ? hs - h : hs);
        }
        if (st.find(hs) != st.end()) {
            cout << "Yes" << endl;
            continue;
        }
        ull hs2;
        for (int i = 0; i < n; i ++) {
            hs2 = hs + h - hss[i];
            hs2 = (hs2 >= h ? hs2 - h : hs2);
            hs2 += h - hss[i + 1];
            hs2 = (hs2 >= h ? hs2 - h : hs2);
            hs2 += mpl(s[i] + 100, Bs[n-i-1]);
            hs2 = (hs2 >= h ? hs2 - h : hs2);
            hs2 += mpl(s[i+1] + 100, Bs[n-i]);
            hs2 = (hs2 >= h ? hs2 - h : hs2);
            ok = ok || (st.find(hs2) != st.end());
        }
        cout << (ok ? "Yes" : "No") << endl;
        st.emplace(hs);
    }
}
0