結果

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

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll x[4] = {-2, -1, 1, 2};

bool solve(string &S) {
    ll N = S.length();
    REP(i, N - 2) {
        ll a = 0, b = 0;
        REP(j, 3) {
            if (S[i + j] == 'o')
                a++;
            if (S[i + j] == '-')
                b++;
        }
        if (a + b == 3 && a > 1)
            return true;
    }
    REP(i, N - 3) {
        if (S[i] != '-' || S[i + 3] != '-')
            continue;
        if (S[i + 1] == 'o' && S[i + 2] == 'o')
            return true;
        if (S[i + 1] == 'o' && S[i + 2] == '-')
            return true;
        if (S[i + 1] == '-' && S[i + 2] == 'o')
            return true;
    }
    ll d = 0;
    bool f = false;
    REP(i, N) {
        if (S[i] == 'x') {
            d = 0;
            f = false;
            continue;
        }

        if (S[i] == '-') {
            if (f)
                d++;
            continue;
        }

        f = true;
        if (d % 2 == 1)
            return true;
        d = 0;
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll T;
    cin >> T;
    REP(i, T) {
        ll N;
        string S;
        cin >> N >> S;
        if (solve(S))
            cout << "O" << endl;
        else
            cout << "X" << endl;
    }
    return 0;
}
0