結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー momoyuu
提出日時 2022-10-15 00:58:43
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,387 bytes
コンパイル時間 3,649 ms
コンパイル使用メモリ 254,704 KB
実行使用メモリ 21,072 KB
最終ジャッジ日時 2024-06-26 18:52:48
合計ジャッジ時間 37,835 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28 WA * 42
権限があれば一括ダウンロードができます

ソースコード

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;
    set<ll> d;
    rep(i,0,n){
        string now;
        cin>>now;
        rhash hash(now,m2,b2);
        bool p =false;
        if(d.find(hash.get(0,now.size()))!=d.end()) p = true;
        rep(i,0,now.size()-1){
            ll nn = hash.inv(i);
            if(d.find(nn)!=d.end())p = true;
            if(p) break;
        }
        d.insert(hash.get(0,now.size()));
        if(p) print("Yes");
        else print("No");
    }
    
    //system("pause");
    return 0;
}
0