QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#416711 | #4234. Tic Tac Toe Counting | Lspeed# | WA | 0ms | 3804kb | C++14 | 3.3kb | 2024-05-22 03:59:24 | 2024-05-22 03:59:25 |
Judging History
answer
#include <iostream> // Input/output stream objects
#include <fstream> // File stream objects
#include <sstream> // String stream objects
#include <iomanip> // Input/output manipulators
#include <string> // String class and functions
#include <vector> // Dynamic array
#include <list> // Doubly linked list
#include <set> // Set container
#include <map> // Map container
#include <queue> // Queue container
#include <stack> // Stack container
#include <algorithm> // Algorithms on sequences (e.g., sort, find)
#include <cmath> // Mathematical functions
#include <climits> // LLONG_MAX, LLONG_MIN
#include <ctime> // Date and time functions
#include <cstdlib> // General purpose functions (e.g., memory management)
#include <cstring> // C-style string functions
#include <cctype> // Character classification functions
#include <cassert> // Assert function for debugging
#include <exception> // Standard exceptions
#include <functional> // Function objects
#include <iterator> // Iterator classes
#include <limits> // Numeric limits
#include <locale> // Localization and internationalization
#include <numeric> // Numeric operations (e.g., accumulate)
#include <random> // Random number generators
#include <stdexcept> // Standard exception classes
#include <typeinfo> // Runtime type information
#include <utility> // Utility components (e.g., std::pair)
#include <bitset>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < (b); i++)
#define FORE(i, a, b) for(int i = a; i <= (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define x first
#define y second
#define mp make_pair
#define PI 3.141592653
#define compress(coord) sort(all(coord)), coord.resize(unique(all(coord)) - coord.begin())
const double eps = 1e-9; // x < eps (x <= 0) x < -eps (x < 0)
const ll inf = LLONG_MAX;
int T, wix, wio;
vi b(11);
bool check_win(int x) {
for (int r = 0; r < 3; r++) {
int st = 3*r;
if (b[st] == x && b[st] == b[st+1] && b[st+1] == b[st+2]) return true; // row
if (b[r] == x && b[r] == b[r + 3] && b[r+3] == b[r+6]) return true; // column
}
if (b[0] == x && b[0] == b[4] && b[4] == b[8]) return true; // diag 1
else if (b[2] == x && b[2] == b[4] && b[4] == b[6]) return true; // diag 2
return false;
}
void sim(int turnx) {
if (check_win(1)) {
wix++;
return ;
}
else if (check_win(0)) {
wio++;
return ;
}
for (int i = 0; i < 9; i++) if (b[i] == -1) {
b[i] = turnx;
sim(turnx ^ 1);
b[i] = -1;
}
return ;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> T;
while (T--) {
string s;
b = vi(9, -1);
wix = 0, wio = 0;
cin >> s;
int cntx = 0, cnto = 0;
FOR (i, 0, 9) {
if (s[i] == 'X') b[i] = 1, cntx++;
else if (s[i] == 'O') b[i] = 0, cnto++;
}
if (abs(cntx - cnto) > 1 || (check_win(1) && check_win(0)) || (cnto > cntx)) {
cout << -1 << endl;
continue ;
}
sim(cntx == cnto);
cout << wix << " " << wio << endl;
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3804kb
input:
4 XX..O.... X...OX... OOOX.X.X. OOOXXX...
output:
191 194 232 200 0 1 -1
result:
wrong answer 4th lines differ - expected: '-1 -1', found: '-1'