結果
| 問題 |
No.1016 三目並べ
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2020-04-03 22:41:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 113 ms / 2,000 ms |
| コード長 | 1,493 bytes |
| コンパイル時間 | 1,469 ms |
| コンパイル使用メモリ | 170,680 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-03 05:01:15 |
| 合計ジャッジ時間 | 2,371 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
string s;
cin >> s;
auto cnt = [&] {
int res = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '-') {
res += (i and s[i - 2] == 'o' and s[i - 1] == 'o') or
(i and i + 1 < n and s[i - 1] == 'o' and s[i + 1] == 'o') or
(i + 2 < n and s[i + 1] == 'o' and s[i + 2] == 'o');
}
}
return res;
};
[&] {
for (int i = 0; i + 3 <= n; ++i) {
int o = count(begin(s) + i, begin(s) + (i + 3), 'o');
int x = count(begin(s) + i, begin(s) + (i + 3), 'x');
int _ = 3 - o - x;
if (o == 3 or (o == 2 and _ == 1)) {
cout << "O\n";
return;
}
}
for (int i = 0; i < n; ++i) {
if (s[i] == '-') {
s[i] = 'o';
if (cnt() >= 2) {
cout << "O\n";
return;
}
s[i] = '-';
}
}
vector<int> idx;
for (int i = 0; i < n; ++i) {
if (s[i] == 'o') {
idx.push_back(i);
}
}
for (int t = 0; t < (int)idx.size() - 1; ++t) {
int i = idx[t], j = idx[t + 1];
if ((j - i) % 2 == 0 and count(begin(s) + i, begin(s) + j, '-') == j - i - 1) {
cout << "O\n";
return;
}
}
cout << "X\n";
}();
}
}
risujiroh