結果
| 問題 | 
                            No.2102 [Cherry Alpha *] Conditional Reflection
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-10-15 00:10:07 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,638 bytes | 
| コンパイル時間 | 2,160 ms | 
| コンパイル使用メモリ | 202,048 KB | 
| 最終ジャッジ日時 | 2025-02-08 05:17:10 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 WA * 66 | 
ソースコード
#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], 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);
    }
}