結果

問題 No.2030 Googol Strings
ユーザー RubikunRubikun
提出日時 2022-08-05 21:40:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,367 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 203,760 KB
実行使用メモリ 36,248 KB
最終ジャッジ日時 2023-10-13 22:16:36
合計ジャッジ時間 3,870 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
4,352 KB
testcase_01 AC 66 ms
4,352 KB
testcase_02 AC 60 ms
9,832 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 WA -
testcase_05 AC 49 ms
4,348 KB
testcase_06 AC 113 ms
36,248 KB
testcase_07 AC 6 ms
5,388 KB
testcase_08 AC 6 ms
5,456 KB
testcase_09 AC 5 ms
4,352 KB
testcase_10 AC 5 ms
4,352 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 117 ms
9,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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)*10;q++){
                A+=S[q%x];
                B+=T[q%y];
            }
            //assert(A!=B);
            if(A<=B) ans=true;
            else ans=false;
        }
        
        ans^=f;
        
        if(ans) cout<<"Y\n";
        else cout<<"X\n";
    }
}
0