結果

問題 No.1016 三目並べ
ユーザー SSRSSSRS
提出日時 2020-04-03 22:25:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,429 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 170,788 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 03:02:58
合計ジャッジ時間 2,342 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 5 ms
4,376 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 < 2) 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] == '-'){
          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] == '-'){
          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