QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#554873#4234. Tic Tac Toe CountingFortitude#TL 1ms3636kbC++231.5kb2024-09-09 16:53:072024-09-09 16:53:07

Judging History

This is the latest submission verdict.

  • [2024-09-09 16:53:07]
  • Judged
  • Verdict: TL
  • Time: 1ms
  • Memory: 3636kb
  • [2024-09-09 16:53:07]
  • Submitted

answer

#include <bits/stdc++.h>
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define f first
#define s second
using namespace std;
using ll = long long;
using pii = pair <int, int>;
const int N = 2e5 + 5;

char s[3][3];
int cnt[2];

bool win(char c){
	for(int i = 0; i < 3; i++){
		if(s[i][0] == c && s[i][1] == c && s[i][2] == c) return 1;
		if(s[0][i] == c && s[1][i] == c && s[2][i] == c) return 1;
	}
	if(s[0][0] == c && s[1][1] == c && s[2][2] == c)
		return 1;
	if(s[0][2] == c && s[1][1] == c && s[2][0] == c)
		return 1;
	return 0;
}
void calc(bool type){
	if(win('X')){
		cnt[0]++;
		return;
	}
	if(win('O')){
		cnt[1]++;
		return;
	}
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			if(s[i][j] == '.'){
				if(!type){
					s[i][j] = 'X';
					calc(type ^ 1);
				}else{
					s[i][j] = 'O';
					calc(type ^ 1);
				}
				s[i][j] = '.';
			}
		}
	}
}
void solve(){
	int cntx = 0, cnty = 0;
	for(int i = 0; i < 9; i++){
		char c;
		cin >> c;
		s[i / 3][i % 3] = c;
		if(c == 'X') cntx++;
		if(c == 'O') cnty++;
	}
	if(cnty > cntx || abs(cntx - cnty) > 1){
		cout << "-1 -1\n";
		return;
	}
	if(win('X') && win('O')){
		cout << "-1 -1\n";
		return;
	}
	cnt[0] = cnt[1] = 0;
	calc(cntx != cnty);
	cout << cnt[0] << " " << cnt[1] << "\n";
}

int main() {
	ios :: sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3636kb

input:

4
XX..O....
X...OX...
OOOX.X.X.
OOOXXX...

output:

191 194
232 200
0 1
-1 -1

result:

ok 4 lines

Test #2:

score: -100
Time Limit Exceeded

input:

100000
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
......

output:


result: