結果

問題 No.1016 三目並べ
ユーザー risujirohrisujiroh
提出日時 2020-04-03 22:22:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,400 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 166,924 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-16 02:37:18
合計ジャッジ時間 2,556 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    auto cnt = [&] {
      int res = 0;
      for (int i = 0; i < n; ++i) {
        if (s[i] == '-') {
          res += (i and s[i - 2] == 'o' and s[i - 1] == 'o') or
                 (i and i + 1 < n and s[i - 1] == 'o' and s[i + 1] == 'o') or
                 (i + 2 < n and s[i + 1] == 'o' and s[i + 2] == 'o');
        }
      }
      return res;
    };
    [&] {
      for (int i = 0; i + 3 <= n; ++i) {
        int o = count(begin(s) + i, begin(s) + (i + 3), 'o');
        int x = count(begin(s) + i, begin(s) + (i + 3), 'x');
        int _ = 3 - o - x;
        if (o == 3 or (o == 2 and _ == 1)) {
          cout << "O\n";
          return;
        }
      }
      for (int i = 0; i < n; ++i) {
        if (s[i] == '-') {
          s[i] = 'o';
          if (cnt() >= 2) {
            cout << "O\n";
            return;
          }
          s[i] = '-';
        }
      }
      for (int w = 2; w < n; w *= 2) {
        for (int i = 0; i + w < n; ++i) {
          if (s[i] == 'o' and s[i + w] == 'o') {
            if (count(begin(s) + (i + 1), begin(s) + (i + w), '-') == w - 1) {
              cout << "O\n";
            }
          }
        }
      }
      cout << "X\n";
    }();
  }
}
0