結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー roarisroaris
提出日時 2022-10-14 23:08:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,662 bytes
コンパイル時間 2,238 ms
コンパイル使用メモリ 207,624 KB
実行使用メモリ 21,524 KB
最終ジャッジ日時 2023-09-08 23:33:42
合計ジャッジ時間 35,927 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 127 ms
21,460 KB
testcase_53 AC 124 ms
21,520 KB
testcase_54 AC 124 ms
21,524 KB
testcase_55 AC 175 ms
4,376 KB
testcase_56 WA -
testcase_57 WA -
testcase_58 AC 125 ms
14,920 KB
testcase_59 WA -
testcase_60 WA -
testcase_61 AC 174 ms
4,376 KB
testcase_62 AC 14 ms
4,376 KB
testcase_63 WA -
testcase_64 AC 120 ms
4,380 KB
testcase_65 AC 125 ms
4,380 KB
testcase_66 AC 165 ms
4,376 KB
testcase_67 AC 342 ms
4,380 KB
testcase_68 AC 118 ms
4,380 KB
testcase_69 AC 345 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct RollingHash {
    vector<long long> acc = {0};
    vector<long long> power = {1};
    int base = 17;
    int mod = 1000000007;
    
    RollingHash(string s) {
        for (int i=0; i<s.size(); i++) {
            acc.push_back((acc.back()*base+(s[i]-'a'))%mod);
            power.push_back(power.back()*base%mod);
        }
    }
    
    long long get(int l, int r) {
        long long h = (acc[r]-acc[l]*power[r-l])%mod;
        if (h<0) h += mod;
        return h;
    }
};

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    
    int N; cin >> N;
    set<long long> ws;
    
    for (int t=0; t<N; t++) {
        string s; cin >> s;
        RollingHash rh(s);
        long long h = rh.get(0, s.size());

        if (ws.find(h)!=ws.end()) cout << "Yes" << endl;
        else {
            bool ok = false;
            
            for (int i=0; i<s.size()-1; i++) {
                long long nh = h;
                nh -= (s[i]-'a')*rh.power[s.size()-1-i]%rh.mod;
                nh %= rh.mod;
                nh -= (s[i+1]-'a')*rh.power[s.size()-2-i]%rh.mod;
                nh %= rh.mod;
                nh += (s[i+1]-'a')*rh.power[s.size()-1-i]%rh.mod;
                nh %= rh.mod;
                nh += (s[i]-'a')*rh.power[s.size()-2-i]%rh.mod;
                nh %= rh.mod;
                if (nh<0) nh += rh.mod;
                if (ws.find(nh)!=ws.end()) {
                    cout << "Yes" << endl;
                    ok = true;
                    break;
                }
            }
            
            if (!ok) cout << "No" << endl;
        }

        ws.insert(h);
    }
}
0