結果

問題 No.1016 三目並べ
ユーザー HaaHaa
提出日時 2020-04-03 22:11:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 1,564 ms
コンパイル使用メモリ 167,728 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 02:04:18
合計ジャッジ時間 2,084 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

string p[2]={"-o--","--o-"};
string q[2]={"oo-","-oo"};

int main(){
	int t; cin >> t;
	while(t--){
		int n; cin >> n;
		string s; cin >> s;
		bool win=0;
		REP(i,n-3){
			REP(j,2){
				bool f=1;
				REP(k,4)if(p[j][k]!=s[i+k])f=0;
				if(f){
					win=1;
					break;
				}
			}
		}
		REP(i,n-2){
			REP(j,2){
				bool f=1;
				REP(k,3)if(q[j][k]!=s[i+k])f=0;
				if(f){
					win=1;
					break;
				}
			}
		}
		bool f=0; int len=0;
		REP(i,n){
			if(s[i]=='o'){
				if(f&&len%2==1){
					win=1;
					len=0;
				}
				f=1;
			}
			else if(s[i]=='-'&&f)
				len++;
			else{
				len=0;
				f=0;
			}
		}
		REP(i,n-2) if(s[i]=='o'&&s[i+1]=='o'&&s[i+2]=='o') win=1;
		if(win)
			cout << 'O' << endl;
		else
			cout << 'X' << endl;
	}
	return 0;
}
0