結果

問題 No.1016 三目並べ
ユーザー risujirohrisujiroh
提出日時 2020-04-03 22:41:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,493 bytes
コンパイル時間 1,516 ms
コンパイル使用メモリ 168,956 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 03:41:57
合計ジャッジ時間 2,580 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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] = '-';
        }
      }
      vector<int> idx;
      for (int i = 0; i < n; ++i) {
        if (s[i] == 'o') {
          idx.push_back(i);
        }
      }
      for (int t = 0; t < (int)idx.size() - 1; ++t) {
        int i = idx[t], j = idx[t + 1];
        if ((j - i) % 2 == 0 and count(begin(s) + i, begin(s) + j, '-') == j - i - 1) {
          cout << "O\n";
          return;
        }
      }
      cout << "X\n";
    }();
  }
}
0