結果

問題 No.2030 Googol Strings
ユーザー baLoon8128baLoon8128
提出日時 2022-08-05 22:25:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,767 bytes
コンパイル時間 4,380 ms
コンパイル使用メモリ 228,552 KB
実行使用メモリ 20,196 KB
最終ジャッジ日時 2023-10-13 23:41:37
合計ジャッジ時間 6,059 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
4,352 KB
testcase_01 AC 22 ms
4,352 KB
testcase_02 AC 20 ms
5,764 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 37 ms
4,356 KB
testcase_05 AC 18 ms
4,348 KB
testcase_06 AC 41 ms
16,812 KB
testcase_07 AC 51 ms
20,196 KB
testcase_08 AC 51 ms
19,992 KB
testcase_09 AC 22 ms
4,352 KB
testcase_10 AC 23 ms
4,348 KB
testcase_11 AC 22 ms
4,376 KB
testcase_12 AC 42 ms
4,348 KB
testcase_13 AC 37 ms
4,376 KB
testcase_14 AC 21 ms
4,352 KB
testcase_15 AC 47 ms
4,960 KB
testcase_16 AC 49 ms
4,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; --i)

struct MP {
    const string word;

    MP(const string &W) : word(W), table(W.size() + 1) {
        table[0] = -1;
        for (int i = 0, j = -1; i < W.size(); i++) {
            while (j >= 0 && W[i] != W[j]) j = table[j];
            ++j;
            table[i + 1] = j;
        }
        return;
    }

    vi searchIn(const string &S) {
        int n = S.size();
        vi ret(n);
        int m = 0, k = 0;
        while (m + k < S.size()) {
            if (S[m + k] == word[k]) {
                k++;
                if (k == word.size()) {
                    ret[m] = k;
                    m = m + k - table[k];
                    k = table[k];
                }
            } else {
                ret[m] = k;
                m = m + k - table[k];
                if (k > 0) k = table[k];
            }
        }
        return ret;
    }

   private:
    vi table;
};

int solve() {
    string x, y;
    cin >> x >> y;
    int r = 0;
    if (x.size() > y.size()) {
        swap(x, y);
        r = 1;
    }
    MP sv(x);
    vi res = sv.searchIn(y + y);
    int nx = x.size(), ny = y.size();
    int c = 0;
    while (1) {
        if (res[c] < nx) {
            int k = res[c];
            if (x[k] > y[(c + k) % ny]) r ^= 1;
            return r;
        }
        c = (c + nx) % ny;
        if (c == 0) break;
    }
    return r;
}
int main() {
    int T;
    cin >> T;
    rep(i, T) cout << (solve() ? 'X' : 'Y') << '\n';
    return 0;
}
0