QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#414953 | #4234. Tic Tac Toe Counting | ivan_len# | WA | 561ms | 3804kb | C++20 | 2.8kb | 2024-05-20 04:58:39 | 2024-05-20 04:58:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define PB push_back
#define MP make_pair
#define A first
#define B second
#define SZ(x) int(x.size())
#define FR(i, a, b) for (int i = (a); i < (b); ++i)
#define FOR(i, n) FR(i, 0, n)
const int M = 1000000007;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n;
int State(vector<vector<int>>& s) {
int win = 0;
FOR(i, 3) {
if (s[i][0] == s[i][1] && s[i][0] == s[i][2]) {
if (s[i][0] == 1) win |= 1;
if (s[i][0] == 2) win |= 2;
}
if (s[0][i] == s[1][i] && s[0][i] == s[2][i]) {
if (s[0][i] == 1) win |= 1;
if (s[0][i] == 2) win |= 2;
}
}
if (s[0][0] == s[1][1] && s[0][0] == s[2][2]) {
if (s[0][0] == 1) win |= 1;
if (s[0][0] == 2) win |= 2;
}
if (s[2][0] == s[1][1] && s[2][0] == s[0][2]) {
if (s[1][1] == 1) win |= 1;
if (s[1][1] == 2) win |= 2;
}
return win;
}
int X, O;
void dfs(vector<vector<int>>& state, int cnt) {
int win = 0;
if (cnt >= 5) win = State(state);
if (win == 3) return;
if (win == 1) {
X++;
return;
}
if (win == 2) {
O++;
return;
}
if (cnt == 9) return;
int c = ((cnt & 1)?2:1);
FOR(i, 3) {
FOR(j, 3) {
if (state[i][j] == 0) {
vector<vector<int>> nxt = state;
nxt[i][j] = c;
dfs(nxt, cnt + 1);
}
}
}
}
// X for 1, O for 2; . for 0
void solve() {
vector<vector<int>> state(3, vector<int>(3));
string s;
cin >> s;
X = 0; O = 0;
FOR(i, 3) {
FOR(j, 3) {
if (s[i * 3 + j] == 'X') state[i][j] = 1;
if (s[i * 3 + j] == 'O') state[i][j] = 2;
}
}
int Xcnt = 0, Ocnt = 0;
FOR(i, 3) {
FOR(j, 3) {
if (state[i][j] == 1) Xcnt++;
if (state[i][j] == 2) Ocnt++;
}
}
if (Xcnt + Ocnt == 0) {
cout << "131184 77904\n";
return;
}
if (Xcnt == 1 && Ocnt == 0) {
if (s[4] == 'X') cout << "15648 5616\n";
else if (s[0] == 'X' || s[2] == 'X' || s[6] == 'X' || s[8] == 'X') cout << "14232 10176\n";
else cout << "14652 7896\n";
return;
}
if (Xcnt < Ocnt || Xcnt > Ocnt + 1) {
cout << "-1 -1\n";
return;
}
if (State(state) == 3) {
cout << "-1 -1\n";
return;
}
dfs(state, Xcnt + Ocnt);
cout << X << ' ' << O << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int numtests;
cin >> numtests;
while(numtests--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 9ms
memory: 3804kb
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: 561ms
memory: 3748kb
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 14232 10176 -1 -1 14652 7896 -1 -1 1798 1276 -1 -1 2048 756 -1 -1 14232 10176 -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 14652 7896 -1 -1 1798 1276 -1 -1 -1 -1 264 188 1868 1080 239 126 -1 -1 -1 -1 -1 -1 312...
result:
wrong answer 2nd lines differ - expected: '14652 7896', found: '14232 10176'