#include "coprobber.h"
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
using namespace std;
struct state{
int u, v, t;
int operator()() const {
return u * MAX_N * 2 + v * 2 + t;
}
string print() const {
string r;
r += "(";
r += to_string(u);
r += ", ";
r += to_string(v);
r += ", ";
r += to_string(t);
r += ")";
return r;
}
};
int id(int u, int v, int t){
return u * MAX_N * 2 + v * 2 + t;
}
int N;
bool w[MAX_N * MAX_N * 2];
int nxt[MAX_N * MAX_N * 2];
int deg[MAX_N * MAX_N * 2], r_deg[MAX_N * MAX_N * 2];
bool added[MAX_N * MAX_N * 2];
bool A[MAX_N][MAX_N];
void add_edge(int u, int v){
// cout << "Edge: " << u.print() << " -> " << v.print() << endl;
if(w[v] == true) deg[u]++; r_deg[u]++;
}
int pos = -1;
int start(int N, bool A[MAX_N][MAX_N])
{
::N = N;
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
::A[i][j] = A[i][j];
}
}
for(int u = 0; u < N; u++){
for(int v = 0; v < N; v++){
for(int t = 0; t < 2; t++){
state st {u, v, t};
if(u == v) w[st()] = true;
}
}
}
for(int u = 0; u < N; u++){
for(int v = 0; v < N; v++){
for(int t = 0; t < 2; t++){
if(u == v) continue;
if(t == 0){
for(int i = 0; i < N; i++){
if(A[u][i] || i == u){
add_edge(id(u, v, t), id(i, v, !t));
}
}
}else{
for(int i = 0; i < N; i++){
if(A[v][i]){
add_edge(id(u, v, t), id(u, i, !t));
}
}
}
}
}
}
vector<int> det;
for(int u = 0; u < N; u++){
for(int v = 0; v < N; v++){
for(int t = 0; t < 2; t++){
state st {u, v, t};
bool alr_win = false;
if(t == 0){
for(int i = 0; i < N; i++){
if(A[u][i] && i == v) alr_win = true;
}
}
if(u != v && (r_deg[st()] == deg[st()] || alr_win)){
det.push_back(st()); added[st()] = true;
}
}
}
}
while(det.size()){
int k = det.back(); det.pop_back();
int u = k / 2 / MAX_N;
int v = k / 2 % MAX_N;
int t = k % 2;
int st = id(u, v, t);
if(t == 0){
bool exist_win = false;
for(int i = 0; i < N; i++){
if(A[u][i] || i == u){
int st2 = id(i, v, !t);
exist_win |= w[st2];
if(w[st2]) nxt[st] = st2;
}
}
w[st] = exist_win;
}else{
bool all_win = true;
for(int i = 0; i < N; i++){
if(A[v][i]){
int st2 = id(u, i, !t);
all_win &= w[st2];
}
}
w[st] = all_win;
}
if(t == 0){
for(int i = 0; i < N; i++){
if(A[i][v]){
int st2 = id(u, i, 1);
if(added[st2]) continue;
deg[st2]++;
if(deg[st2] == r_deg[st2]) added[st2] = true, det.push_back(st2);
else if((!t) == 0 && w[st] == 1) added[st2] = true, det.push_back(st2);
else if((!t) == 1 && w[st] == 0) added[st2] = true, det.push_back(st2);
}
}
}else{
for(int i = 0; i < N; i++){
if(A[i][u] || i == u){
int st2 = id(i, v, 0);
if(added[st2]) continue;
deg[st2]++;
if(deg[st2] == r_deg[st2]) added[st2] = true, det.push_back(st2);
else if((!t) == 0 && w[st] == 1) added[st2] = true, det.push_back(st2);
else if((!t) == 1 && w[st] == 0) added[st2] = true, det.push_back(st2);
}
}
}
}
for(int i = 0; i < N; i++){
bool all_win = true;
for(int j = 0; j < N; j++){
state st {i, j, 0};
all_win &= w[st()];
}
if(all_win){
pos = i;
return i;
}
}
return -1;
}
int nextMove(int R)
{
state st {pos, R, 0};
int st2 = nxt[st()];
pos = st2 / 2 / MAX_N;
return pos;
}
Compilation message
coprobber.cpp: In function 'void add_edge(int, int)':
coprobber.cpp:38:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
38 | if(w[v] == true) deg[u]++; r_deg[u]++;
| ^~
coprobber.cpp:38:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
38 | if(w[v] == true) deg[u]++; r_deg[u]++;
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
0 ms |
464 KB |
Output is correct |
4 |
Correct |
607 ms |
8788 KB |
Output is correct |
5 |
Correct |
70 ms |
4260 KB |
Output is correct |
6 |
Correct |
690 ms |
8656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
464 KB |
Output is correct |
3 |
Correct |
626 ms |
8520 KB |
Output is correct |
4 |
Correct |
612 ms |
8740 KB |
Output is correct |
5 |
Correct |
582 ms |
8384 KB |
Output is correct |
6 |
Correct |
656 ms |
8604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
0 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
4 ms |
1744 KB |
Output is correct |
11 |
Correct |
9 ms |
1804 KB |
Output is correct |
12 |
Correct |
1 ms |
720 KB |
Output is correct |
13 |
Correct |
2 ms |
1360 KB |
Output is correct |
14 |
Correct |
7 ms |
1744 KB |
Output is correct |
15 |
Correct |
2 ms |
1104 KB |
Output is correct |
16 |
Correct |
3 ms |
1104 KB |
Output is correct |
17 |
Correct |
15 ms |
2040 KB |
Output is correct |
18 |
Correct |
4 ms |
1744 KB |
Output is correct |
19 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
0 ms |
464 KB |
Output is correct |
4 |
Correct |
607 ms |
8788 KB |
Output is correct |
5 |
Correct |
70 ms |
4260 KB |
Output is correct |
6 |
Correct |
690 ms |
8656 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
464 KB |
Output is correct |
9 |
Correct |
626 ms |
8520 KB |
Output is correct |
10 |
Correct |
612 ms |
8740 KB |
Output is correct |
11 |
Correct |
582 ms |
8384 KB |
Output is correct |
12 |
Correct |
656 ms |
8604 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
592 KB |
Output is correct |
22 |
Correct |
4 ms |
1744 KB |
Output is correct |
23 |
Correct |
9 ms |
1804 KB |
Output is correct |
24 |
Correct |
1 ms |
720 KB |
Output is correct |
25 |
Correct |
2 ms |
1360 KB |
Output is correct |
26 |
Correct |
7 ms |
1744 KB |
Output is correct |
27 |
Correct |
2 ms |
1104 KB |
Output is correct |
28 |
Correct |
3 ms |
1104 KB |
Output is correct |
29 |
Correct |
15 ms |
2040 KB |
Output is correct |
30 |
Correct |
4 ms |
1744 KB |
Output is correct |
31 |
Correct |
0 ms |
336 KB |
Output is correct |
32 |
Correct |
0 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
0 ms |
464 KB |
Output is correct |
35 |
Correct |
598 ms |
8732 KB |
Output is correct |
36 |
Correct |
77 ms |
4384 KB |
Output is correct |
37 |
Correct |
672 ms |
8600 KB |
Output is correct |
38 |
Correct |
0 ms |
336 KB |
Output is correct |
39 |
Correct |
0 ms |
464 KB |
Output is correct |
40 |
Correct |
602 ms |
8640 KB |
Output is correct |
41 |
Correct |
637 ms |
8748 KB |
Output is correct |
42 |
Correct |
599 ms |
8380 KB |
Output is correct |
43 |
Correct |
676 ms |
8600 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
0 ms |
336 KB |
Output is correct |
46 |
Correct |
0 ms |
484 KB |
Output is correct |
47 |
Correct |
1 ms |
592 KB |
Output is correct |
48 |
Correct |
4 ms |
1744 KB |
Output is correct |
49 |
Correct |
12 ms |
1732 KB |
Output is correct |
50 |
Correct |
1 ms |
720 KB |
Output is correct |
51 |
Correct |
3 ms |
1360 KB |
Output is correct |
52 |
Correct |
10 ms |
1696 KB |
Output is correct |
53 |
Correct |
3 ms |
1104 KB |
Output is correct |
54 |
Correct |
3 ms |
1104 KB |
Output is correct |
55 |
Correct |
15 ms |
2032 KB |
Output is correct |
56 |
Correct |
4 ms |
1744 KB |
Output is correct |
57 |
Correct |
27 ms |
3164 KB |
Output is correct |
58 |
Correct |
170 ms |
6096 KB |
Output is correct |
59 |
Correct |
324 ms |
7624 KB |
Output is correct |
60 |
Correct |
953 ms |
9676 KB |
Output is correct |
61 |
Correct |
789 ms |
7356 KB |
Output is correct |
62 |
Correct |
783 ms |
8000 KB |
Output is correct |
63 |
Correct |
825 ms |
9284 KB |
Output is correct |
64 |
Correct |
391 ms |
7820 KB |
Output is correct |
65 |
Execution timed out |
1748 ms |
9324 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |