結果
問題 |
No.2030 Googol Strings
|
ユーザー |
|
提出日時 | 2024-10-06 20:38:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 64 ms / 2,000 ms |
コード長 | 2,096 bytes |
コンパイル時間 | 1,200 ms |
コンパイル使用メモリ | 119,516 KB |
最終ジャッジ日時 | 2025-02-24 16:11:23 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include<iostream> #include<string> #include<queue> #include<vector> #include<cassert> #include<random> #include<set> #include<map> #include<cassert> #include<unordered_map> #include<bitset> #include<numeric> #include<algorithm> using namespace std; typedef long long ll; const int inf=1<<30; const ll INF=1LL<<62; typedef pair<int,ll> P; typedef pair<int,P> PP; const ll MOD=998244353; const int MAX=1000000; vector<ll> divisor(ll n){ vector<ll> res; for(ll d=1;d*d<=n;d++){ if(n%d==0){ res.push_back(d); if(d*d!=n){ res.push_back(n/d); } } } return res; } string cycle_check(string s){ int n=s.size(); auto res=divisor(s.size()); int cand_len=s.size(); string ans=s; for(int len:res){ int t=n/len; bool ok=true; for(int i=0;i<len;i++){ for(int j=1;i+j*len<n;j++){ if(s[i]!=s[i+j*len]){ ok=false; break; } } } if(ok){ if(cand_len>len){ ans=s.substr(0,len); cand_len=len; } } } return ans; } char solve(){ string x,y; cin>>x; cin>>y; bool overlap=true; { /* xyzxyzxyz xyzxyz */ string cX=cycle_check(x),cY=cycle_check(y); if(cX==cY) { if(x.size()>y.size()){ return 'X'; }else{ return 'Y'; } }else { overlap=false; } } int lenx=x.size(); int leny=y.size(); for(int i=0;i<MAX;i++){ if(x[i%lenx]!=y[i%leny]){ if(x[i%lenx]>y[i%leny]){ return 'X'; }else{ return 'Y'; } } } return 'X'; } int main(){ int T; cin>>T; vector<char> ans(T); for(int t=0;t<T;t++){ ans[t]=solve(); } for(int t=0;t<T;t++){ cout<<ans[t]<<endl; } }