結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2022-10-15 00:13:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,005 ms / 3,000 ms
コード長 1,642 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 208,080 KB
実行使用メモリ 20,292 KB
最終ジャッジ日時 2023-09-09 01:06:50
合計ジャッジ時間 52,250 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
11,196 KB
testcase_01 AC 76 ms
11,232 KB
testcase_02 AC 480 ms
15,612 KB
testcase_03 AC 581 ms
16,012 KB
testcase_04 AC 519 ms
15,488 KB
testcase_05 AC 424 ms
13,288 KB
testcase_06 AC 563 ms
15,704 KB
testcase_07 AC 637 ms
13,252 KB
testcase_08 AC 249 ms
11,344 KB
testcase_09 AC 518 ms
15,560 KB
testcase_10 AC 299 ms
12,180 KB
testcase_11 AC 251 ms
13,344 KB
testcase_12 AC 427 ms
14,124 KB
testcase_13 AC 630 ms
16,432 KB
testcase_14 AC 450 ms
13,816 KB
testcase_15 AC 604 ms
15,512 KB
testcase_16 AC 758 ms
17,072 KB
testcase_17 AC 402 ms
13,248 KB
testcase_18 AC 575 ms
13,972 KB
testcase_19 AC 332 ms
13,412 KB
testcase_20 AC 667 ms
16,664 KB
testcase_21 AC 363 ms
11,564 KB
testcase_22 AC 849 ms
17,440 KB
testcase_23 AC 838 ms
17,440 KB
testcase_24 AC 852 ms
17,384 KB
testcase_25 AC 852 ms
17,480 KB
testcase_26 AC 844 ms
17,408 KB
testcase_27 AC 841 ms
17,376 KB
testcase_28 AC 852 ms
17,352 KB
testcase_29 AC 859 ms
17,376 KB
testcase_30 AC 827 ms
17,432 KB
testcase_31 AC 830 ms
17,336 KB
testcase_32 AC 848 ms
17,408 KB
testcase_33 AC 842 ms
17,372 KB
testcase_34 AC 876 ms
17,356 KB
testcase_35 AC 864 ms
17,500 KB
testcase_36 AC 824 ms
17,312 KB
testcase_37 AC 799 ms
17,360 KB
testcase_38 AC 825 ms
17,412 KB
testcase_39 AC 829 ms
17,436 KB
testcase_40 AC 847 ms
17,384 KB
testcase_41 AC 843 ms
17,444 KB
testcase_42 AC 659 ms
15,800 KB
testcase_43 AC 675 ms
15,920 KB
testcase_44 AC 676 ms
15,920 KB
testcase_45 AC 655 ms
15,672 KB
testcase_46 AC 660 ms
15,800 KB
testcase_47 AC 579 ms
13,404 KB
testcase_48 AC 577 ms
13,496 KB
testcase_49 AC 566 ms
13,588 KB
testcase_50 AC 551 ms
13,396 KB
testcase_51 AC 577 ms
13,472 KB
testcase_52 AC 979 ms
19,788 KB
testcase_53 AC 974 ms
19,796 KB
testcase_54 AC 972 ms
19,788 KB
testcase_55 AC 998 ms
11,204 KB
testcase_56 AC 1,002 ms
11,264 KB
testcase_57 AC 1,000 ms
11,264 KB
testcase_58 AC 979 ms
16,760 KB
testcase_59 AC 900 ms
20,292 KB
testcase_60 AC 256 ms
11,232 KB
testcase_61 AC 1,005 ms
11,224 KB
testcase_62 AC 95 ms
11,460 KB
testcase_63 AC 254 ms
11,200 KB
testcase_64 AC 256 ms
11,224 KB
testcase_65 AC 260 ms
11,204 KB
testcase_66 AC 995 ms
11,252 KB
testcase_67 AC 464 ms
11,156 KB
testcase_68 AC 983 ms
11,284 KB
testcase_69 AC 460 ms
11,148 KB
権限があれば一括ダウンロードができます

ソースコード

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