結果

問題 No.1016 三目並べ
ユーザー fura
提出日時 2020-06-20 07:02:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 681 bytes
コンパイル時間 2,219 ms
コンパイル使用メモリ 193,108 KB
最終ジャッジ日時 2025-01-11 08:27:36
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:39:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         int q; scanf("%d",&q); rep(_,q) solve();
      |                ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

bool check(string s){
	int n=s.length();
	// o???...(odd)...?o
	if(n>=3 && n%2==1 && s[0]=='o' && s[n-1]=='o') return true;
	// oo?, ?oo
	rep(i,n-2){
		if(s[ i ]=='o' && s[i+1]=='o') return true;
		if(s[i+1]=='o' && s[i+2]=='o') return true;
	}
	// ?o??, ??o?
	rep(i,n-3){
		if(s[i+1]=='o' || s[i+2]=='o') return true;
	}
	return false;
}

void solve(){
	int n;
	string s; cin>>n>>s;

	int pre=0;
	rep(i,n+1) if(i==n || s[i]=='x') {
		if(check(s.substr(pre,i-pre))){
			puts("O");
			return;
		}
		pre=i+1;
	}
	puts("X");
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}
0