QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#19241#2405. Tic-Tac StateQingyuAC ✓5ms3712kbC++201.5kb2022-01-28 16:10:432022-05-06 04:30:03

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-06 04:30:03]
  • 评测
  • 测评结果:AC
  • 用时:5ms
  • 内存:3712kb
  • [2022-01-28 16:10:43]
  • 提交

answer

#include <bits/stdc++.h>

int map[3][3];
char s[1005];

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		int S;
		scanf("%o", &S);
		bool finished = true;
		for (int i = 0; i < 3; ++i) 
			for (int j = 0; j < 3; ++j) {
				int o = 3 * i + j;
				if (S >> o & 1)	
					map[i][j] = 0;
				else {
					map[i][j] = -1;
					finished = false;
				}
			}
		for (int i = 0; i < 3; ++i) 
			for (int j = 0; j < 3; ++j) {
				int o = 3 * i + j;
				if (map[i][j] == 0) {
					if (S >> o + 9 & 1)
						map[i][j] = 2;
					else 
						map[i][j] = 1;
				}
			}
		auto solve = [&]() {
			for (int i = 0; i < 3; ++i) {
				bool ok = true;
				if (map[i][0] == -1) continue;
				for (int j = 1; j < 3; ++j) {
					if (map[i][0] != map[i][j]) {
						ok = false;
					}
				}
				if (ok) return map[i][0];
			}
			for (int i = 0; i < 3; ++i) {
				bool ok = true;
				if (map[0][i] == -1) continue;
				for (int j = 1; j < 3; ++j) {
					if (map[0][i] != map[j][i]) {
						ok = false;
					}
				}
				if (ok) return map[0][i];
			}
			if (map[1][1] == -1)
				return -1;
			if (map[0][0] == map[1][1] && map[1][1] == map[2][2])
				return map[1][1];
			if (map[0][2] == map[1][1] && map[1][1] == map[2][0])
				return map[1][1];
			return -1;
		};
		int o = solve();
		if (o == -1) {
			if (!finished) {
				puts("In progress");
			}
			else {
				puts("Cat's");
			}
		}
		else if (o == 1) puts("O wins");
		else puts("X wins");
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3628kb

input:

4
01116777
07037
01416777
050055

output:

O wins
X wins
Cat's
In progress

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 3512kb

input:

1
00

output:

In progress

result:

ok single line: 'In progress'

Test #3:

score: 0
Accepted
time: 5ms
memory: 3712kb

input:

5477
01000004
01000001
01000002
01000010
020021
01020025
020022
01020026
020024
01000020
01020023
01020034
020030
01020031
01020032
040041
01040045
040042
01040046
040044
01000040
01040043
01040054
040050
01040051
01040052
01020064
01040064
040060
020060
060063
01060067
060065
01020061
01040061
0600...

output:

In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
...

result:

ok 5477 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

5477
020020
01020024
01020021
01020022
01020030
040040
01040044
01040041
01040042
01040050
060061
01060065
060062
01060066
060064
01020060
01040060
01060063
01060074
060070
01060071
01060072
0100100
01100104
01100101
01100102
01100110
0120121
01120125
0120122
01120126
0120124
01020120
01100120
01120...

output:

In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
In progress
...

result:

ok 5477 lines