結果

問題 No.1016 三目並べ
ユーザー ei13337ei13337
提出日時 2020-04-03 23:18:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,223 bytes
コンパイル時間 1,632 ms
コンパイル使用メモリ 166,644 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-16 04:45:34
合計ジャッジ時間 2,246 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 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 4 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int calc_win(int w, int l, int r) {
    if(w % 2 == 0) return 0;
    if(l == 1 && r == 1) return 1;
    else return 0;
}

int main() {
    int t;
    cin >> t;
    for(int tt = 0; tt < t; tt++) {
        int n;
        cin >> n;
        string s;
        cin >> s;
        bool win = false;
        for(int i = 1; i < n - 1; i++) {
            if(s[i - 1] == 'o' && s[i] == 'o' && s[i + 1] == 'o') win = true;
        }
        int w = 0, l = 0, r = 0;
        for(int i = 0; i < n; i++) {
            if(s[i] != '-') continue;
            w++;
            if(i == 0 || s[i - 1] != '-') {
                if(i && s[i - 1] == 'o') l = 1;
                if(i > 1 && s[i - 1] == 'o' && s[i - 2] == 'o') l = 2;
            }
            if(i == n - 1 || s[i + 1] != '-') {
                if(i < n - 1 && s[i + 1] == 'o') r = 1;
                if(i < n - 2 && s[i + 1] == 'o' && s[i + 2] == 'o') r = 2;
                if(l == 2 || r == 2) win = true;
                if(calc_win(w, l, r)) win = true;
                w = 0; l = 0; r = 0;;
            }
        }
        if(win) cout << "O" << endl;
        else cout << "X" << endl;
    }
    return 0;
}
0