結果

問題 No.2030 Googol Strings
ユーザー Iván Soto
提出日時 2022-08-06 02:53:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,368 bytes
コンパイル時間 1,953 ms
コンパイル使用メモリ 195,292 KB
最終ジャッジ日時 2025-01-30 18:58:10
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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;
  while (tt--) {
    string x, y;
    cin >> 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;
    for (int i = 0; i < 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 (m % (n - f[n]) == 0) {
      if (ans == -1) {
        ans = (n < m ? 0 : 1);
      }
    } else {
      if (ans == -1) {
        int r = m % (n - f[n]);
        for (int i = 0, j = 0; i < n; i++, j++) {
          if (x[(i + r) % n] < y[j % m]) {
            ans = 0;
            break;
          }
          if (x[(i + r) % n] > y[j % m]) {
            ans = 1;
            break;
          }
        }
      }
      assert(ans != -1);
    }
    ans ^= sw;
    cout << (ans == 0 ? "Y" : "X") << '\n';
  }
  return 0;
}
0