結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー momoyuumomoyuu
提出日時 2022-10-15 01:03:11
言語 C++23(draft)
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 904 ms / 3,000 ms
コード長 2,784 bytes
コンパイル時間 3,653 ms
コンパイル使用メモリ 260,672 KB
実行使用メモリ 54,068 KB
最終ジャッジ日時 2023-09-09 01:37:35
合計ジャッジ時間 45,279 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 538 ms
13,064 KB
testcase_03 AC 597 ms
15,192 KB
testcase_04 AC 559 ms
13,072 KB
testcase_05 AC 454 ms
7,784 KB
testcase_06 AC 627 ms
13,052 KB
testcase_07 AC 351 ms
9,972 KB
testcase_08 AC 254 ms
4,376 KB
testcase_09 AC 511 ms
15,156 KB
testcase_10 AC 303 ms
6,104 KB
testcase_11 AC 204 ms
8,540 KB
testcase_12 AC 440 ms
10,660 KB
testcase_13 AC 643 ms
16,792 KB
testcase_14 AC 496 ms
9,272 KB
testcase_15 AC 697 ms
13,176 KB
testcase_16 AC 885 ms
17,620 KB
testcase_17 AC 257 ms
9,284 KB
testcase_18 AC 462 ms
12,568 KB
testcase_19 AC 344 ms
8,556 KB
testcase_20 AC 695 ms
17,588 KB
testcase_21 AC 415 ms
4,584 KB
testcase_22 AC 884 ms
19,140 KB
testcase_23 AC 863 ms
19,004 KB
testcase_24 AC 878 ms
19,004 KB
testcase_25 AC 888 ms
19,120 KB
testcase_26 AC 882 ms
18,968 KB
testcase_27 AC 891 ms
19,124 KB
testcase_28 AC 891 ms
18,968 KB
testcase_29 AC 896 ms
19,044 KB
testcase_30 AC 890 ms
19,004 KB
testcase_31 AC 865 ms
18,952 KB
testcase_32 AC 883 ms
19,024 KB
testcase_33 AC 869 ms
19,008 KB
testcase_34 AC 843 ms
19,000 KB
testcase_35 AC 896 ms
18,944 KB
testcase_36 AC 875 ms
19,124 KB
testcase_37 AC 871 ms
19,000 KB
testcase_38 AC 875 ms
19,260 KB
testcase_39 AC 884 ms
19,112 KB
testcase_40 AC 873 ms
19,120 KB
testcase_41 AC 887 ms
19,052 KB
testcase_42 AC 601 ms
15,480 KB
testcase_43 AC 592 ms
15,412 KB
testcase_44 AC 595 ms
15,360 KB
testcase_45 AC 592 ms
15,536 KB
testcase_46 AC 604 ms
15,544 KB
testcase_47 AC 425 ms
11,488 KB
testcase_48 AC 428 ms
11,340 KB
testcase_49 AC 430 ms
11,368 KB
testcase_50 AC 434 ms
11,196 KB
testcase_51 AC 431 ms
11,368 KB
testcase_52 AC 163 ms
54,000 KB
testcase_53 AC 160 ms
54,068 KB
testcase_54 AC 162 ms
53,820 KB
testcase_55 AC 180 ms
4,376 KB
testcase_56 AC 179 ms
4,380 KB
testcase_57 AC 179 ms
4,376 KB
testcase_58 AC 170 ms
29,064 KB
testcase_59 AC 904 ms
21,352 KB
testcase_60 AC 254 ms
4,376 KB
testcase_61 AC 179 ms
4,380 KB
testcase_62 AC 19 ms
4,380 KB
testcase_63 AC 236 ms
4,376 KB
testcase_64 AC 234 ms
4,380 KB
testcase_65 AC 237 ms
4,376 KB
testcase_66 AC 176 ms
4,376 KB
testcase_67 AC 525 ms
4,380 KB
testcase_68 AC 161 ms
4,376 KB
testcase_69 AC 526 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<class t> using vc = vector<t>;
template<class t> using vvc = vc<vc<t>>;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vi = vc<int>;
using vvi = vvc<int>;
using vl = vc<ll>;
using vvl = vvc<ll>;

#define rep(i,a,b) for (int i = (int)(a); i < (int)(b); i++)
#define irep(i,a,b) for (int i = (int)(a); i > (int)(b); i--)
#define all(a) a.begin(),a.end()
#define print(n) cout << n << '\n'
#define pritn(n) print(n)
#define printv(n,a) {copy(all(n),ostream_iterator<a>(cout," ")); cout<<"\n";}
#define printvv(n,a) {for(auto itr:n) printv(itr,a);}
#define rup(a,b) (a+b-1)/b
#define input(A,N) rep(i,0,N) cin>>A[i]
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

const ll m2 = 1000000007;
const ll b2 = 1009;
const ll m3 = 1000000009;
const ll b3 = 2009;
const ll m4 = 2147483587;
const ll b4 = 2147483583;
//https://gist.github.com/privet-kitty/295ac9202b7abb3039b493f8238bf40f#file-modulus-random-base-pair64-txt
struct rhash{
    int n;
    ll mod,B;
    vc<ll> sum;
    vc<ll> powb;
    string s;
    rhash(string &s,ll mod,ll B):mod(mod),B(B),s(s){
        n = s.size();
        sum = vc<ll>(n+1,0);
        powb = vc<ll>(n+1,1);
        for(int i = 0;i<n;i++){
            sum[i+1] = (sum[i]*B%mod+(s[i]))%mod;
            powb[i+1] = (powb[i]*B)%mod;
        }
    }
    ll get(int l,int r){
        ll tmp = sum[r] - sum[l]*powb[r-l]%mod;
        if(tmp<0) tmp += mod;
        return tmp;
    }

    ll inv(int i){
        ll tmp = sum[n];
        tmp -= powb[n-i-1]*(s[i]) + powb[n-i-2]*(s[i+1]);
        tmp += powb[n-i-2]*(s[i]) + powb[n-i-1]*(s[i+1]);
        tmp %= mod;
        if(tmp<0) tmp += mod;
        return tmp;
    }
};


int main(){
    cout << fixed << setprecision(15);
    
    int n;
    cin>>n;
    // unordered_set<string> d;
    vc<unordered_set<ll>> d(3);
    vl ms = {m2,m3,m4};
    vl bs = {b2,b3,b4};
    rep(i,0,n){
        string now;
        cin>>now;
        vc<rhash> hs;
        rep(i,0,3){
            hs.push_back(rhash(now,ms[i],bs[i]));
        }
        bool p = true;
        rep(i,0,3){
            if(d[i].find(hs[i].get(0,now.size()))!=d[i].end()) continue;
            p = false;
        }
        rep(i,0,now.size()-1){
            bool q = true;
            rep(j,0,3){
                ll nn = hs[j].inv(i);
                if(d[j].find(nn)!=d[j].end())continue;
                q = false;
                break;
            }
            if(q) p = true;
            if(p) break;
        }

        rep(i,0,3){
            d[i].insert(hs[i].get(0,now.size()));
        }
        if(p) print("Yes");
        else print("No");
    }
    
    //system("pause");
    return 0;
}
0