結果
| 問題 |
No.2030 Googol Strings
|
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2022-08-05 21:44:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 144 ms / 2,000 ms |
| コード長 | 2,471 bytes |
| コンパイル時間 | 2,078 ms |
| コンパイル使用メモリ | 200,220 KB |
| 最終ジャッジ日時 | 2025-01-30 17:53:54 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 16 |
ソースコード
#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(si(S)%x) x=si(S);
if(si(T)%y) y=si(T);
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)*10;q++){
A+=S[q%x];
B+=T[q%y];
}
//assert(A!=B);
if(A<=B) ans=true;
else ans=false;
//cout<<A<<" "<<B<<endl;
}
ans^=f;
if(ans) cout<<"Y\n";
else cout<<"X\n";
}
}
Rubikun