#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
int n, m, a, b, p, nxt[505][505], in[505][505];
bool u[505][505][2], t;
vector<int> v[505];
queue<pair<pii, pii> > q;
#define top front
int start (int N, bool A[][500]){
fox(l, N){
fox(l2, N){
if (A[l][l2]) {
v[l].pb(l2);
fox(l3, N){
in[l3][l2]++;
}
}
}
}
fox(l, N){
q.push(mp(mp(l, l), mp(0, -1)));
q.push(mp(mp(l, l), mp(1, -1)));
}
while(!q.empty()){
a=q.top().x.x; b=q.top().x.y; t=q.top().y.x; p=q.top().y.y; q.pop();
if (u[a][b][t]) continue;
if (t) nxt[a][b]=p;
u[a][b][t]=1;
//cout << a << ' ' << b << ' ' << t<< endl;
if (t){
fox(l, v[b].size()){
in[a][v[b][l]]--;
if (in[a][v[b][l]]==0){
if (!u[a][v[b][l]][!t])
q.push(mp(mp(a, v[b][l]), mp(!t, b)));
}
}
} else {
fox(l, v[a].size()){
if (!u[v[a][l]][b][!t])
q.push(mp(mp(v[a][l], b), mp(!t, a)));
}
if (!u[a][b][!t])
q.push(mp(mp(a, b), mp(!t, a)));
}
}
fox(l, N){
bool f=1;
fox(l2, N){
if (u[l][l2][1]==0){
f=0;
break;
}
}
if (f){
return l;
}
}
return -1;
}
int nextMove(int R){
m=R;
if (n==m) return n;
n=nxt[n][m];
return n;
}
/*int main(){
int n;
bool a[500][500];
cin >> n;
fox(l, n) fox(l2, n) cin >> a[l][l2];
//fox(l, n) fox(l2, n) cout << dp[l][l2][0];
cout << start(n, a);
}*/
Compilation message
coprobber.cpp: In function 'int start(int, bool (*)[500])':
coprobber.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
coprobber.cpp:54:17:
fox(l, v[b].size()){
~~~~~~~~~~~~~~
coprobber.cpp:54:13: note: in expansion of macro 'fox'
fox(l, v[b].size()){
^~~
coprobber.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
coprobber.cpp:62:17:
fox(l, v[a].size()){
~~~~~~~~~~~~~~
coprobber.cpp:62:13: note: in expansion of macro 'fox'
fox(l, v[a].size()){
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
58 ms |
4280 KB |
Output is correct |
5 |
Correct |
17 ms |
2308 KB |
Output is correct |
6 |
Correct |
66 ms |
4724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
66 ms |
4692 KB |
Output is correct |
4 |
Correct |
57 ms |
4344 KB |
Output is correct |
5 |
Correct |
62 ms |
4636 KB |
Output is correct |
6 |
Correct |
62 ms |
4216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
896 KB |
Output is correct |
11 |
Correct |
5 ms |
1024 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
768 KB |
Output is correct |
14 |
Correct |
4 ms |
896 KB |
Output is correct |
15 |
Correct |
3 ms |
768 KB |
Output is correct |
16 |
Correct |
3 ms |
768 KB |
Output is correct |
17 |
Correct |
8 ms |
1408 KB |
Output is correct |
18 |
Correct |
3 ms |
896 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
300 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
55 ms |
4340 KB |
Output is correct |
5 |
Correct |
16 ms |
2304 KB |
Output is correct |
6 |
Correct |
67 ms |
4732 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
66 ms |
4632 KB |
Output is correct |
10 |
Correct |
58 ms |
4344 KB |
Output is correct |
11 |
Correct |
65 ms |
4592 KB |
Output is correct |
12 |
Correct |
94 ms |
4216 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
896 KB |
Output is correct |
18 |
Correct |
4 ms |
1024 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
0 ms |
768 KB |
Output is correct |
21 |
Correct |
4 ms |
896 KB |
Output is correct |
22 |
Correct |
3 ms |
768 KB |
Output is correct |
23 |
Correct |
4 ms |
768 KB |
Output is correct |
24 |
Correct |
9 ms |
1408 KB |
Output is correct |
25 |
Correct |
3 ms |
896 KB |
Output is correct |
26 |
Correct |
6 ms |
1408 KB |
Output is correct |
27 |
Correct |
17 ms |
2560 KB |
Output is correct |
28 |
Correct |
30 ms |
3192 KB |
Output is correct |
29 |
Correct |
920 ms |
9464 KB |
Output is correct |
30 |
Correct |
104 ms |
4600 KB |
Output is correct |
31 |
Correct |
104 ms |
4656 KB |
Output is correct |
32 |
Correct |
804 ms |
73588 KB |
Output is correct |
33 |
Correct |
67 ms |
4032 KB |
Output is correct |
34 |
Correct |
690 ms |
11896 KB |
Output is correct |
35 |
Correct |
91 ms |
7660 KB |
Output is correct |
36 |
Correct |
374 ms |
21616 KB |
Output is correct |
37 |
Correct |
120 ms |
4836 KB |
Output is correct |
38 |
Correct |
2 ms |
384 KB |
Output is correct |