結果

問題 No.1016 三目並べ
ユーザー potoooooooopotoooooooo
提出日時 2020-04-03 21:56:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,072 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 166,348 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 01:18:26
合計ジャッジ時間 2,008 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

string a = "-o--";
string b = "--o-";
string c = "ooo";
string d = "oo-";
string e = "-oo";

void solve() {
    int n; string s;
    cin >> n >> s;
    auto judge = [&](int i, string &t) {
        if (i + t.size() > n) return false;
        for (int j = 0; j < t.size(); j++) {
            if (s[i+j] != t[j]) return false; 
        }
        return true;
    };
    bool ok = false;
    for (int i = 0; i < n; i++) {
        ok |= judge(i, a);
        ok |= judge(i, b);
        ok |= judge(i, c);
        ok |= judge(i, d);
        ok |= judge(i, e);
    }
    int c = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '-') c++;
        else {
            if ((c & 1) && c != i) {
                if (s[i-c-1] == 'o' && s[i] == 'o') {
                    ok = true;
                }
            }
            c = 0;
        }
    }
    if (ok) cout << "O\n";
    else cout << "X\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t; cin >> t;
    while (t--) solve();
    return 0;
}
0