結果
問題 | No.2102 [Cherry Alpha *] Conditional Reflection |
ユーザー | momoyuu |
提出日時 | 2022-10-15 01:03:11 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 905 ms / 3,000 ms |
コード長 | 2,784 bytes |
コンパイル時間 | 3,506 ms |
コンパイル使用メモリ | 261,972 KB |
実行使用メモリ | 54,160 KB |
最終ジャッジ日時 | 2024-06-26 18:55:15 |
合計ジャッジ時間 | 44,817 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 70 |
ソースコード
#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; }