結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー 👑 AngrySadEightAngrySadEight
提出日時 2022-10-15 00:48:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,175 ms / 3,000 ms
コード長 5,354 bytes
コンパイル時間 4,704 ms
コンパイル使用メモリ 272,936 KB
実行使用メモリ 91,172 KB
最終ジャッジ日時 2024-06-26 18:46:23
合計ジャッジ時間 58,571 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
26,772 KB
testcase_01 AC 18 ms
26,772 KB
testcase_02 AC 636 ms
59,852 KB
testcase_03 AC 733 ms
64,280 KB
testcase_04 AC 633 ms
54,276 KB
testcase_05 AC 434 ms
41,876 KB
testcase_06 AC 726 ms
60,208 KB
testcase_07 AC 699 ms
73,488 KB
testcase_08 AC 207 ms
31,148 KB
testcase_09 AC 694 ms
65,496 KB
testcase_10 AC 289 ms
37,400 KB
testcase_11 AC 260 ms
42,548 KB
testcase_12 AC 489 ms
50,160 KB
testcase_13 AC 892 ms
80,524 KB
testcase_14 AC 515 ms
47,592 KB
testcase_15 AC 772 ms
60,800 KB
testcase_16 AC 1,067 ms
84,168 KB
testcase_17 AC 408 ms
56,456 KB
testcase_18 AC 762 ms
74,316 KB
testcase_19 AC 389 ms
43,768 KB
testcase_20 AC 961 ms
80,872 KB
testcase_21 AC 342 ms
34,584 KB
testcase_22 AC 1,116 ms
83,648 KB
testcase_23 AC 1,142 ms
83,784 KB
testcase_24 AC 1,150 ms
83,776 KB
testcase_25 AC 1,150 ms
83,928 KB
testcase_26 AC 1,150 ms
83,788 KB
testcase_27 AC 1,159 ms
83,788 KB
testcase_28 AC 1,175 ms
83,664 KB
testcase_29 AC 1,161 ms
83,664 KB
testcase_30 AC 1,134 ms
83,788 KB
testcase_31 AC 1,136 ms
83,784 KB
testcase_32 AC 1,171 ms
83,788 KB
testcase_33 AC 1,150 ms
83,776 KB
testcase_34 AC 1,119 ms
83,788 KB
testcase_35 AC 1,136 ms
83,788 KB
testcase_36 AC 1,125 ms
83,776 KB
testcase_37 AC 1,128 ms
83,776 KB
testcase_38 AC 1,121 ms
83,652 KB
testcase_39 AC 1,109 ms
83,672 KB
testcase_40 AC 1,139 ms
83,792 KB
testcase_41 AC 1,122 ms
83,788 KB
testcase_42 AC 652 ms
51,852 KB
testcase_43 AC 674 ms
51,728 KB
testcase_44 AC 699 ms
51,848 KB
testcase_45 AC 661 ms
51,716 KB
testcase_46 AC 653 ms
51,852 KB
testcase_47 AC 759 ms
76,808 KB
testcase_48 AC 773 ms
76,936 KB
testcase_49 AC 755 ms
76,936 KB
testcase_50 AC 734 ms
76,932 KB
testcase_51 AC 768 ms
76,880 KB
testcase_52 AC 551 ms
69,092 KB
testcase_53 AC 517 ms
68,960 KB
testcase_54 AC 524 ms
69,096 KB
testcase_55 AC 617 ms
70,100 KB
testcase_56 AC 601 ms
70,104 KB
testcase_57 AC 684 ms
69,980 KB
testcase_58 AC 101 ms
28,356 KB
testcase_59 AC 1,164 ms
91,172 KB
testcase_60 AC 200 ms
30,128 KB
testcase_61 AC 623 ms
70,100 KB
testcase_62 AC 32 ms
27,536 KB
testcase_63 AC 202 ms
30,884 KB
testcase_64 AC 231 ms
30,792 KB
testcase_65 AC 270 ms
31,164 KB
testcase_66 AC 602 ms
69,852 KB
testcase_67 AC 426 ms
32,916 KB
testcase_68 AC 105 ms
28,832 KB
testcase_69 AC 424 ms
33,020 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