結果

問題 No.1016 三目並べ
ユーザー KoDKoD
提出日時 2020-04-03 21:56:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 2,076 bytes
コンパイル時間 693 ms
コンパイル使用メモリ 78,308 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 01:19:21
合計ジャッジ時間 1,428 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int solve() {
  int N;
  std::string S;
  std::cin >> N >> S;
  for (int i: range(0, N - 2)) {
    auto tmp = S.substr(i, 3);
    if (tmp == "oo-" || tmp == "o-o" || tmp == "-oo" || tmp == "ooo") {
      std::cout << "O\n";
      return 0;
    }
  }
  for (int i: range(0, N - 3)) {
    auto tmp = S.substr(i, 4);
    if (tmp == "-o--" || tmp == "--o-") {
      std::cout << "O\n";
      return 0;
    }
  }
  int last = -1;
  for (int i: range(0, N)) {
    if (S[i] == 'o') {
      if (last != -1 && (i - last) % 2 == 0) {
        std::cout << "O\n";
        return 0;
      }
      last = i;
    }
    else if (S[i] == 'x') {
      last = -1;
    }
  }
  std::cout << "X\n";
  return 0;
}

int main() {
  int T;
  std::cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
0