QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#413058#4234. Tic Tac Toe CountingDanielChang#WA 31ms4048kbC++171.6kb2024-05-17 01:49:262024-05-17 01:49:26

Judging History

This is the latest submission verdict.

  • [2024-05-17 01:49:26]
  • Judged
  • Verdict: WA
  • Time: 31ms
  • Memory: 4048kb
  • [2024-05-17 01:49:26]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

map<string, pair<int,int>> mp;

int check(string &s){
	int cntX=0, cntO=0;
	for(char c : s){
		if(c == 'X') cntX++;
		if(c == 'O') cntO++;
	}
	if(!(cntX == cntO) && !(cntX == cntO+1)) return -2;

	int X=0, O=0;
	for(int i=0; i<9; i+=3){
		if(s[i]==s[i+1] && s[i+1]==s[i+2]){
			if(s[i]=='X') X++;
			if(s[i]=='O') O++;
		}
	}
	for(int i=0; i<3; i++){
		if(s[i]==s[i+3] && s[i+3]==s[i+6]){
			if(s[i]=='X') X++;
			if(s[i]=='O') O++;
		}
	}
	if((s[0]==s[4] && s[4]==s[8]) || (s[2]==s[4] && s[4]==s[6])){
		if(s[4]=='X') X++;
		if(s[4]=='O') O++;
	}
	if(X == 1 && O == 0) return 1;
	if(X == 0 && O == 1) return -1;
	if(X == 2 && O == 0 && cntX == 5) return 1;
	if(X || O) return -2;
	return 0;
}

pair<int,int> dfs(string &s, bool turn){
	if(mp.count(s)) return mp[s];
	int c = check(s);
	assert(c != -2);
	if(c == 1){
		return mp[s] = {1, 0};
	}
	if(c == -1){
		return mp[s] = {0, 1};
	}
	pair<int,int> res{0,0};
	for(int i=0; i<9; i++){
		if(s[i] == '.'){
			s[i] = !turn ? 'X' : 'O';
			auto [X, O] = dfs(s, !turn);
			res.first += X;
			res.second += O;
			s[i]='.';
		}
	}
	return mp[s] = res;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	string s = string(9, '.');
	bool turn = 0;
	dfs(s, turn);
	int t;
	cin >> t;
	while(t--){
		string a;
		cin >> a;
		if(check(a) == -2){
			cout << -1 << " " << -1 << endl;
		}
		else{
			cout << mp[a].first << " " << mp[a].second << endl;
		}
	}
}
// gcc a.cpp -std=gnu++14 -o a.exe
// g++ a.cpp -g -O2 -std=gnu++14 -static -o a.exe

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 3832kb

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: 0
Accepted
time: 31ms
memory: 4048kb

input:

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

output:

131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
131184 77904
1...

result:

ok 100000 lines

Test #3:

score: -100
Wrong Answer
time: 24ms
memory: 3916kb

input:

100000
.........
X........
O........
.X.......
XX.......
OX.......
.O.......
XO.......
OO.......
..X......
X.X......
O.X......
.XX......
XXX......
OXX......
.OX......
XOX......
OOX......
..O......
X.O......
O.O......
.XO......
XXO......
OXO......
.OO......
XOO......
OOO......
...X.....
X..X.....
O.....

output:

131184 77904
14652 7896
-1 -1
14232 10176
-1 -1
1798 1276
-1 -1
2048 756
-1 -1
14652 7896
-1 -1
1832 1132
-1 -1
-1 -1
220 248
2048 756
268 144
-1 -1
-1 -1
1832 1132
-1 -1
1798 1276
220 248
-1 -1
-1 -1
-1 -1
-1 -1
14232 10176
-1 -1
1798 1276
-1 -1
-1 -1
264 188
1868 1080
239 126
-1 -1
-1 -1
-1 -1
312...

result:

wrong answer 882nd lines differ - expected: '-1 -1', found: '0 0'