結果
問題 | No.2030 Googol Strings |
ユーザー |
![]() |
提出日時 | 2022-08-05 21:35:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,346 bytes |
コンパイル時間 | 2,103 ms |
コンパイル使用メモリ | 199,160 KB |
最終ジャッジ日時 | 2025-01-30 17:47:09 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 WA * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; } #define all(x) (x).begin(),(x).end() #define fi first #define se second #define mp make_pair #define si(x) int(x.size()) const int mod=998244353,MAX=200005,INF=1<<30; struct KMP{ vector<int> A; string S; void init(string &T){ S=T; A.assign(S.size()+1,0); A[0]=-1; int j=-1; for(int i=0;i<S.size();i++){ while(j>=0&&S[i]!=S[j]) j=A[j]; j++; A[i+1]=j; } } vector<int> match(string &C,string &T){ init(C); vector<int> B; int m=0,i=0; while(m+i<T.size()){ if(S[i]==T[m+i]){ i++; if(i==S.size()){ B.push_back(m); m+=i-A[i]; i=A[i]; } }else{ m+=i-A[i]; if(i>0) i=A[i]; } } return B; }//C(=S)がTの中に含まれる開始位置を返す }; int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int Q;cin>>Q; while(Q--){ bool f=false; string S,T;cin>>S>>T; if(si(S)>si(T)){ swap(S,T); f=true; } if(si(S)==si(T)){ if(S<T) cout<<"Y\n"; else cout<<"X\n"; continue; } bool ans=false; KMP s,t; s.init(S);t.init(T); int x=si(S)-s.A.back(),y=si(T)-t.A.back(); if(x==y){ if(S.substr(0,x)<T.substr(0,x)) ans=true; else if(S.substr(0,x)==T.substr(0,x)) ans=true; else ans=false; }else{ string A,B; for(int q=0;q<si(T)*2;q++){ A+=S[q%si(S)]; B+=T[q%si(T)]; } if(A<=B) ans=true; else ans=false; } ans^=f; if(ans) cout<<"Y\n"; else cout<<"X\n"; } }