結果

問題 No.2030 Googol Strings
ユーザー Iván SotoIván Soto
提出日時 2022-08-06 03:21:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,790 bytes
コンパイル時間 1,905 ms
コンパイル使用メモリ 201,440 KB
実行使用メモリ 9,004 KB
最終ジャッジ日時 2023-10-14 05:22:30
合計ジャッジ時間 3,257 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,348 KB
testcase_01 AC 3 ms
4,352 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 8 ms
4,348 KB
testcase_05 AC 5 ms
4,352 KB
testcase_06 AC 11 ms
6,664 KB
testcase_07 AC 17 ms
8,952 KB
testcase_08 AC 18 ms
9,004 KB
testcase_09 AC 13 ms
4,348 KB
testcase_10 AC 13 ms
4,352 KB
testcase_11 AC 13 ms
4,348 KB
testcase_12 AC 16 ms
4,352 KB
testcase_13 AC 15 ms
4,352 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 20 ms
4,348 KB
testcase_16 AC 17 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <algo/debug.h>
#else
#define debug(...) 42
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  int qq = 0;
  while (tt--) {
    string x, y;
    cin >> x >> y;
    ++qq;
    if (qq == 58) debug(qq, x, y);
    int sw = 0;
    if (x.size() > y.size()) {
      swap(x, y);
      sw = 1;
    }
    int n = (int) x.size();
    vector<int> f(n + 1);
    f[0] = -1;
    for (int i = 0, j = -1; i < n; i++, j++) {
      while (j != -1 && x[i] != x[j]) {
        j = f[j];
      }
      f[i + 1] = j + 1;
    }
    int m = (int) y.size();
    int ans = -1;
    int last_x = -1;
    for (int i = 0; i < 2 * m; i++) {
      int px = i % n;
      int py = i % m;
      if (x[px] < y[py]) {
        ans = 0;
        break;
      }
      if (x[px] > y[py]) {
        ans = 1;
        break;
      }
    }
    debug(ans, sw);
    if (n % (n - f[n]) == 0) {
      debug("period", n - f[n]);
      if (m % (n - f[n]) == 0) {
        debug("ok");
        if (ans == -1) {
          ans = (n < m ? 0 : 1);
        }
      } else {
        if (ans == -1) {
          int r = m % (n - f[n]);
          debug(n, m, r, n - f[n]);
          for (int i = 0, j = 0; i < n; i++, j++) {
            if (x[(i + r) % (n - f[n])] < y[j % m]) {
              ans = 0;
              debug("here", ans);
              break;
            }
            if (x[(i + r) % (n - f[n])] > y[j % m]) {
              ans = 1;
              debug("here", ans);
              break;
            }
          }
        }
      }
    } else {
      if (m % n == 0 && ans == -1) {
        ans = (n < m ? 0 : 1);
      }
    }
    assert(ans != -1);
    ans ^= sw;
    cout << (ans == 0 ? "Y" : "X") << '\n';
  }
  return 0;
}
0