結果

問題 No.1016 三目並べ
ユーザー kyort0nkyort0n
提出日時 2020-04-03 21:47:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,481 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 168,272 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 00:56:38
合計ジャッジ時間 2,160 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;

bool check(string S) {
    //cerr << S << endl;
    ll num = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'o') num++;
    }
    if(num >= 3) return true;
    if(num == 0) return false;
    if(num == 1) {
        if(S.size() <= 3 or S.back() == 'o' or S[0] == 'o') return false;
        return true;
    }
    if((int)S.size() % 2 == 0 and S[0] == 'o' and S.back() == 'o') return false;
    return true;
}

void solve() {
    ll N;
    string S;
    cin >> N >> S;
    S = "x" + S + "x";
    ll Last = 0;
    //cerr << S << endl;
    for(int i = 1; i < S.size(); i++) {
        if(S[i] == 'x') {
            if(i - Last - 1 > 0 and check(S.substr(Last+1, i-Last-1))) {
                cout << "O" << endl;
                return;
            }
            Last = i;
        }
    }
    cout << "X" << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    while(N--) solve();
    return 0;
}
0