QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#416721#4234. Tic Tac Toe CountingLspeed#WA 56ms4404kbC++143.5kb2024-05-22 04:11:262024-05-22 04:11:27

Judging History

This is the latest submission verdict.

  • [2024-05-22 04:11:27]
  • Judged
  • Verdict: WA
  • Time: 56ms
  • Memory: 4404kb
  • [2024-05-22 04:11:26]
  • Submitted

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;
string s = ".........";
map<string, pair<ll, ll>> m;

bool check_win(string s, char x) {
    for (int r = 0; r < 3; r++) {
        int st = 3*r;
        if (s[st] == x && s[st] == s[st+1] && s[st+1] == s[st+2]) return true; // row
        if (s[r] == x && s[r] == s[r + 3] && s[r+3] == s[r+6]) return true; // column
    }

    if (s[0] == x && s[0] == s[4] && s[4] == s[8]) return true; // diag 1
    else if (s[2] == x && s[2] == s[4] && s[4] == s[6]) return true; // diag 2
    return false;
}

void sim(int turnx) {
    if (m.find(s) != m.end()) return ;

    if (check_win(s, 'X')) {
        m[s] = mp(1, 0);
        return ;
    }
    else if (check_win(s, 'O')) {
        m[s] = mp(0, 1);
        return ;
    }

    string pres(s);
    m[s] = mp(0, 0);
    for (int i = 0; i < 9; i++) if (s[i] == '.') {
        s[i] = turnx ? 'X' : 'O';    
        sim(turnx ^ 1);
        pair<ll, ll> ret = m[s];
        m[pres].x += ret.x; m[pres].y += ret.y;
        s[i] = '.';
    }
    return ;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> T;
    sim(true);
    while (T--) {
        string ts;
        cin >> ts;
        int cntx = 0, cnto = 0;
        FOR (i, 0, 9) {
            if (ts[i] == 'X') cntx++;
            else if (ts[i] == 'O') cnto++;
        }
        if (abs(cntx - cnto) > 1 || (check_win(ts, 'X') && check_win(ts, 'O')) || (cnto > cntx)) {
            cout << "-1 -1" << endl;
            continue;
        }
        cout << m[ts].x << " " << m[ts].y << endl;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 4196kb

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: 56ms
memory: 4404kb

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: 23ms
memory: 4140kb

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'