結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー AngrySadEightAngrySadEight
提出日時 2022-10-15 00:48:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,306 ms / 3,000 ms
コード長 5,354 bytes
コンパイル時間 4,718 ms
コンパイル使用メモリ 270,972 KB
実行使用メモリ 91,000 KB
最終ジャッジ日時 2023-09-09 01:28:38
合計ジャッジ時間 62,900 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
26,508 KB
testcase_01 AC 18 ms
26,668 KB
testcase_02 AC 651 ms
59,752 KB
testcase_03 AC 748 ms
64,080 KB
testcase_04 AC 621 ms
54,180 KB
testcase_05 AC 435 ms
41,588 KB
testcase_06 AC 741 ms
59,844 KB
testcase_07 AC 758 ms
73,420 KB
testcase_08 AC 205 ms
31,052 KB
testcase_09 AC 715 ms
65,332 KB
testcase_10 AC 287 ms
37,148 KB
testcase_11 AC 273 ms
42,188 KB
testcase_12 AC 520 ms
49,768 KB
testcase_13 AC 995 ms
80,368 KB
testcase_14 AC 560 ms
47,364 KB
testcase_15 AC 823 ms
60,412 KB
testcase_16 AC 1,144 ms
83,876 KB
testcase_17 AC 422 ms
56,140 KB
testcase_18 AC 781 ms
74,332 KB
testcase_19 AC 364 ms
43,880 KB
testcase_20 AC 996 ms
80,556 KB
testcase_21 AC 333 ms
34,468 KB
testcase_22 AC 1,230 ms
83,764 KB
testcase_23 AC 1,225 ms
83,392 KB
testcase_24 AC 1,214 ms
83,456 KB
testcase_25 AC 1,234 ms
83,576 KB
testcase_26 AC 1,251 ms
83,504 KB
testcase_27 AC 1,202 ms
83,560 KB
testcase_28 AC 1,224 ms
83,616 KB
testcase_29 AC 1,238 ms
83,648 KB
testcase_30 AC 1,272 ms
83,560 KB
testcase_31 AC 1,235 ms
83,612 KB
testcase_32 AC 1,182 ms
83,612 KB
testcase_33 AC 1,229 ms
83,600 KB
testcase_34 AC 1,213 ms
83,608 KB
testcase_35 AC 1,198 ms
83,572 KB
testcase_36 AC 1,240 ms
83,436 KB
testcase_37 AC 1,230 ms
83,540 KB
testcase_38 AC 1,264 ms
83,456 KB
testcase_39 AC 1,226 ms
83,628 KB
testcase_40 AC 1,221 ms
83,616 KB
testcase_41 AC 1,187 ms
83,552 KB
testcase_42 AC 711 ms
51,336 KB
testcase_43 AC 761 ms
51,404 KB
testcase_44 AC 765 ms
51,524 KB
testcase_45 AC 748 ms
51,408 KB
testcase_46 AC 777 ms
51,572 KB
testcase_47 AC 824 ms
76,768 KB
testcase_48 AC 810 ms
76,608 KB
testcase_49 AC 799 ms
76,616 KB
testcase_50 AC 833 ms
76,776 KB
testcase_51 AC 815 ms
76,612 KB
testcase_52 AC 537 ms
68,824 KB
testcase_53 AC 550 ms
68,824 KB
testcase_54 AC 607 ms
68,892 KB
testcase_55 AC 720 ms
69,836 KB
testcase_56 AC 770 ms
69,944 KB
testcase_57 AC 761 ms
69,888 KB
testcase_58 AC 97 ms
28,212 KB
testcase_59 AC 1,306 ms
91,000 KB
testcase_60 AC 198 ms
30,040 KB
testcase_61 AC 775 ms
69,892 KB
testcase_62 AC 31 ms
27,236 KB
testcase_63 AC 200 ms
30,828 KB
testcase_64 AC 218 ms
30,496 KB
testcase_65 AC 266 ms
31,060 KB
testcase_66 AC 735 ms
69,628 KB
testcase_67 AC 422 ms
32,800 KB
testcase_68 AC 104 ms
28,736 KB
testcase_69 AC 422 ms
32,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define mod1 1000000007
#define mod2 998244353
#define mod3 100000007
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vvl vector<vector<ll>>
#define vvvi vector<vector<vector<int>>>
#define vvvl vector<vector<vector<ll>>>
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define vvpii vector<vector<pair<int,int>>>
#define vvpll vector<vector<pair<ll,ll>>>

template<typename T> void debug(T e){
    cerr << e << endl;
}

template<typename T> void debug(vector<T> &v){
    rep(i, v.size()){
        cerr << v[i] << " ";
    }
    cerr << endl;
}

template<typename T> void debug(vector<vector<T>> &v){
    rep(i, v.size()){
        rep(j, v[i].size()){
            cerr << v[i][j] << " ";
        }
        cerr << endl;
    }
}

template<typename T> void debug(vector<pair<T, T>> &v){
    rep(i,v.size()){
        cerr << v[i].first << " " << v[i].second << endl;
    }
}

template<typename T> void debug(set<T> &st){
    for (auto itr = st.begin(); itr != st.end(); itr++){
        cerr << *itr << " ";
    }
    cerr << endl;
}

template<typename T> void debug(multiset<T> &ms){
    for (auto itr = ms.begin(); itr != ms.end(); itr++){
        cerr << *itr << " ";
    }
    cerr << endl;
}

template<typename T> void debug(map<T, T> &mp){
    for (auto itr = mp.begin(); itr != mp.end(); itr++){
        cerr << itr->first << " " << itr->second << endl;
    }
}

void debug_out(){
    cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
    cerr << H << " ";
    debug_out(T...);
}

ll mk_hash(string S, ll h, ll mod){
    ll num = 1;
    ll ret = 0;
    for (ll i = 0; i < S.size(); i++){
        ret = (ret * h) % mod;
        ret = (ret + (S[i] - 'a')) % mod;
    }
    return ret;
}

ll to_single_val(ll hashs, ll len){
    return hashs * 1000000 + len;
}


int main(){
    int N;
    cin >> N;
    vs S(N);
    unordered_map<ll, ll> mp1;
    unordered_map<ll, ll> mp2;
    unordered_map<ll, ll> mp3;
    rep(i,N) cin >> S[i];
    ll h1 = 1009;
    ll h2 = 997;
    ll h3 = 991;
    vl pows1(1000002);
    vl pows2(1000002);
    vl pows3(1000002);
    pows1[0] = 1;
    pows2[0] = 1;
    pows3[0] = 1;
    for (ll i = 0; i < 1000001; i++){
        pows1[i + 1] = (pows1[i] * h1) % mod1;
        pows2[i + 1] = (pows2[i] * h2) % mod2;
        pows3[i + 1] = (pows3[i] * h3) % mod3;
    }

    for (ll i = 0; i < N; i++){
        bool pos = false;
        ll hash1 = mk_hash(S[i], h1, mod1);
        ll hash2 = mk_hash(S[i], h2, mod2);
        ll hash3 = mk_hash(S[i], h3, mod3);
        if (mp1[to_single_val(hash1, S[i].size())] && mp2[to_single_val(hash2, S[i].size())] && mp3[to_single_val(hash3, S[i].size())]){
            pos = true;
        }
        ll len = S[i].size();
        for (ll j = 0; j < len - 1; j++){
            ll new_hash1 = hash1;
            new_hash1 = (new_hash1 - ((ll)(S[i][j] - 'a') * pows1[len - 1 - j]) % mod1 + mod1) % mod1;
            new_hash1 = (new_hash1 + ((ll)(S[i][j + 1] - 'a') * pows1[len - 1 - j]) % mod1 + mod1) % mod1;
            new_hash1 = (new_hash1 - ((ll)(S[i][j + 1] - 'a') * pows1[len - 1 - (j + 1)]) % mod1 + mod1) % mod1;
            new_hash1 = (new_hash1 + ((ll)(S[i][j] - 'a') * pows1[len - 1 - (j + 1)]) % mod1 + mod1) % mod1;

            ll new_hash2 = hash2;
            new_hash2 = (new_hash2 - ((ll)(S[i][j] - 'a') * pows2[len - 1 - j]) % mod2 + mod2) % mod2;
            new_hash2 = (new_hash2 + ((ll)(S[i][j + 1] - 'a') * pows2[len - 1 - j]) % mod2 + mod2) % mod2;
            new_hash2 = (new_hash2 - ((ll)(S[i][j + 1] - 'a') * pows2[len - 1 - (j + 1)]) % mod2 + mod2) % mod2;
            new_hash2 = (new_hash2 + ((ll)(S[i][j] - 'a') * pows2[len - 1 - (j + 1)]) % mod2 + mod2) % mod2;

            ll new_hash3 = hash3;
            new_hash3 = (new_hash3 - ((ll)(S[i][j] - 'a') * pows3[len - 1 - j]) % mod3 + mod3) % mod3;
            new_hash3 = (new_hash3 + ((ll)(S[i][j + 1] - 'a') * pows3[len - 1 - j]) % mod3 + mod3) % mod3;
            new_hash3 = (new_hash3 - ((ll)(S[i][j + 1] - 'a') * pows3[len - 1 - (j + 1)]) % mod3 + mod3) % mod3;
            new_hash3 = (new_hash3 + ((ll)(S[i][j] - 'a') * pows3[len - 1 - (j + 1)]) % mod3 + mod3) % mod3;
            //debug(new_hash);
            //debug(to_single_val(new_hash, S[i].size()));
            if (mp1[to_single_val(new_hash1, S[i].size())] && mp2[to_single_val(new_hash2, S[i].size())] && mp3[to_single_val(new_hash3, S[i].size())]){
                pos = true;
            }
            /*if (mp[pll(new_hash, S[i].size())]){
                pos = true;
            }*/
        }
        if (pos) cout << "Yes" << endl;
        else cout << "No" << endl;
        mp1[to_single_val(hash1, S[i].size())]++;
        mp2[to_single_val(hash2, S[i].size())]++;
        mp3[to_single_val(hash3, S[i].size())]++;
    }
}
0