結果
| 問題 |
No.1016 三目並べ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-11 15:00:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 2,258 bytes |
| コンパイル時間 | 4,500 ms |
| コンパイル使用メモリ | 202,796 KB |
| 最終ジャッジ日時 | 2025-01-09 17:23:06 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 10 |
ソースコード
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
map<string, int> memo[2];
int test(string &s, int t) {
if (memo[t].count(s))return memo[t][s];
int &res = memo[t][s];
int n = sz(s);
rep(i, n - 2) {
int cnt = 0;
FOR(j, i, i + 3) if (s[j] == 'o')cnt++;
if (cnt == 3) return res = 1;
}
int cnt = 0;
rep(i, n)if (s[i] == '-') {
s[i] = t ? 'x' : 'o';
int ret = test(s, 1 - t);
s[i] = '-';
if (t && !ret)return res = 0;
if (!t && ret)return res = 1;
cnt++;
}
if (cnt == 0)return res = 0;
return res = t;
}
void solve() {
//for (int S = 0; S < (1 << 7); ++S) {
// string T(7, '-');
// rep(i, 7)if (S >> i & 1)T[i] = 'o';
// cout << test(T, 0) << ' ' << T << endl;
//}
string V[] = { "--o-", "-o--", "oo-", "-oo", "ooo" };
int T;
cin >> T;
while (T--) {
int N;
string S;
cin >> N >> S;
char ans = [&] {
for (auto U : V) {
rep(i, N - sz(U) + 1) {
int win = 1;
rep(j, sz(U)) if (S[i + j] != U[j])win = 0;
if (win) return 'O';
}
}
int pre = N;
rep(i, N) {
if (S[i] == 'o') {
int d = i - pre;
if (d > 1 && d % 2 == 0) return 'O';
pre = i;
} else if (S[i] == 'x') {
pre = N;
}
}
return 'X';
}();
cout << ans << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
}