結果

問題 No.2030 Googol Strings
ユーザー HaaHaa
提出日時 2022-08-05 21:51:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,501 bytes
コンパイル時間 1,882 ms
コンパイル使用メモリ 172,072 KB
実行使用メモリ 7,644 KB
最終ジャッジ日時 2023-10-13 22:33:43
合計ジャッジ時間 5,685 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
7,644 KB
testcase_01 AC 24 ms
4,352 KB
testcase_02 AC 22 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 41 ms
4,352 KB
testcase_05 AC 20 ms
4,352 KB
testcase_06 AC 31 ms
5,576 KB
testcase_07 AC 42 ms
6,972 KB
testcase_08 AC 43 ms
6,892 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

void solve(){
    string x, y;
    cin >> x >> y;
    int n=x.size(), m=y.size();
    int g=__gcd(n,m);
    bool same=1;
    VI f(26,-1);
    REP(i,n){
        if(f[x[i]-'a']==-1){
            f[x[i]-'a']=i%g;
        }
        else{
            if(f[x[i]-'a']!=i%g){
                same=0;
                break;
            }
        }
    }
    REP(i,m){
        if(f[y[i]-'a']==-1){
            f[y[i]-'a']=i%g;
        }
        else{
            if(f[y[i]-'a']!=i%g){
                same=0;
                break;
            }
        }
    }
    set<int> st;
    REP(i,26){
        if(f[i]!=-1){
            if(st.find(f[i])!=st.end()){
                same=0;
                break;
            }
            st.insert(f[i]);
        }
    }
    if(same){
        cout << (n>m?'X':'Y') << endl;
    }
    else{
        for(int i=0;1;i++){
            if(x[i%n]!=y[i%m]){
                cout << (x[i%n]>y[i%m]?'X':'Y') << endl;
                break;
            }
        }
    }
}

int main(){
    int t; cin >> t;
    while(t--) solve();
    return 0;
}
0