結果

問題 No.1016 三目並べ
ユーザー SSRSSSRS
提出日時 2020-04-03 22:21:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,433 bytes
コンパイル時間 1,662 ms
コンパイル使用メモリ 172,276 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-16 02:36:34
合計ジャッジ時間 2,412 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
bool solve(string &S){
  int N = S.size();
  vector<string> P;
  for (int i = 0; i < N; i++){
    if (S[i] == 'x'){
      P.push_back("");
    } else {
      P[P.size() - 1] += S[i];
    }
  }
  int C = P.size();
  for (int i = 0; i < C; i++){
    string p = P[i];
    int L = P[i].size();
    if (L < 3) continue;
    //A: -oo-でなくooを含む
    if (p != "-oo-"){
      for (int j = 0; j < L - 1; j++){
        if (p[j] == 'o' && p[j + 1] == 'o'){
          return true;
        }
      }
    }
    //B: oで始まるか終わり-o-を含む
    if (p[0] == 'o' || p[L - 1] == 'o'){
      for (int j = 1; j < L - 1; j++){
        if (p[j - 1] == '-' && p[j] == 'o' && p[j + 1] == 'o'){
          return true;
        }
      }
    }
    //C: -o-でなく-o-を含む
    if (p != "-o-"){
      for (int j = 1; j < L - 1; j++){
        if (p[j - 1] == '-' && p[j] == 'o' && p[j + 1] == 'o'){
          return true;
        }
      }
    }
    //D: oで始まりoで終わり長さが奇数
    if (L % 2 == 1){
      if (p[0] == 'o' && p[L - 1] == 'o'){
        return true;
      } else {
        continue;
      }
    }
  }
  return false;
}
int main(){
  int t;
  cin >> t;
  for (int i = 0; i < t; i++){
    int N;
    cin >> N;
    string S;
    cin >> S;
    S = 'x' + S + 'x';
    if (solve(S)){
      cout << 'O' << endl;
    } else {
      cout << 'X' << endl;
    }
  }
}
0