# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
282330 |
2020-08-24T10:08:14 Z |
Noam13 |
Toy Train (IOI17_train) |
C++14 |
|
288 ms |
1664 KB |
#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
#define ii pair<int, int>
#define x first
#define y second
#define vii vector<ii>
#define pb push_back
#define all(x) x.begin(), x.end()
#define loop(i,s,e) for(int i=s;i<e;++i)
#define loopr(i,s,e) for(int i=e-1;i>=s;--i)
#define chkmin(a,b) a = min(a,b)
#define chkmax(a,b) a = max(a,b)
using namespace std;
const int INF = 1e9;
int n;
vvi g, ag;
vi a,r;
vi res;
vb f(vb& s, int who){ // a = 1, b = 0
vb check(n,0);
vi deg(n);
loop(i,0,n) deg[i] = g[i].size();
queue<int> q;
loop(i,0,n) if(s[i]) q.push(i), check[i]=1, deg[i]=0;
while(q.size()){
int cur = q.front(); q.pop();
for(auto nei:ag[cur]){
if (res[nei]!=-1) continue;
if (a[nei]==who){
if (!check[nei]){
check[nei] = 1;
q.push(nei);
}
}
else{
if (--deg[nei]==0){
check[nei] = 1;
q.push(nei);
}
}
}
}
return check;
}
vi who_wins(vi aa, vi rr, vi u, vi v) {
a = aa, r = rr;
n = a.size();
g.resize(n); ag.resize(n);
loop(i,0,u.size()){
int a = u[i], b = v[i];
g[a].pb(b);
ag[b].pb(a);
}
res.resize(n,-1);
while(1){
vb b(n);
loop(i,0,n) if(r[i] && res[i]==-1){
b[i] = 1;
}
b = f(b, 1);
int cnt = 0, sz=0, cnt2=0;
loop(i,0,n) if(res[i]==-1) cnt2+=b[i], b[i]=!b[i], sz++;
if (cnt2==sz || sz==0){
loop(i,0,n) if(res[i]==-1) res[i]=1;
break;
}
b = f(b,0);
loop(i,0,n) if(b[i]) cnt++;
if (cnt==0){
loop(i,0,n) if(res[i]==-1) res[i]=1;
break;
}
loop(i,0,n) if(b[i]) res[i]=0;
}
return res;
}
/*
clear
g++ c.cpp grader.cpp -o c ; ./c
6 7
0 1 0 0 1 0
1 0 0 0 0 1
0 1
1 2
2 3
3 1
4 5
5 5
4 1
*/
Compilation message
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:12:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | #define loop(i,s,e) for(int i=s;i<e;++i)
......
56 | loop(i,0,u.size()){
| ~~~~~~~~~~~~
train.cpp:56:5: note: in expansion of macro 'loop'
56 | loop(i,0,u.size()){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1152 KB |
Output is correct |
2 |
Correct |
9 ms |
1152 KB |
Output is correct |
3 |
Correct |
6 ms |
1152 KB |
Output is correct |
4 |
Correct |
7 ms |
1152 KB |
Output is correct |
5 |
Correct |
6 ms |
1152 KB |
Output is correct |
6 |
Correct |
7 ms |
1152 KB |
Output is correct |
7 |
Correct |
6 ms |
1152 KB |
Output is correct |
8 |
Correct |
6 ms |
1152 KB |
Output is correct |
9 |
Correct |
7 ms |
1152 KB |
Output is correct |
10 |
Correct |
6 ms |
1152 KB |
Output is correct |
11 |
Correct |
5 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Incorrect |
1 ms |
256 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
1656 KB |
Output is correct |
2 |
Correct |
203 ms |
1536 KB |
Output is correct |
3 |
Correct |
288 ms |
1536 KB |
Output is correct |
4 |
Correct |
10 ms |
1408 KB |
Output is correct |
5 |
Incorrect |
11 ms |
1664 KB |
3rd lines differ - on the 11th token, expected: '0', found: '1' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1280 KB |
Output is correct |
2 |
Correct |
10 ms |
1536 KB |
Output is correct |
3 |
Correct |
10 ms |
1664 KB |
Output is correct |
4 |
Correct |
10 ms |
1664 KB |
Output is correct |
5 |
Correct |
10 ms |
1664 KB |
Output is correct |
6 |
Correct |
10 ms |
1664 KB |
Output is correct |
7 |
Correct |
11 ms |
1664 KB |
Output is correct |
8 |
Correct |
10 ms |
1664 KB |
Output is correct |
9 |
Correct |
9 ms |
1536 KB |
Output is correct |
10 |
Correct |
10 ms |
1664 KB |
Output is correct |
11 |
Correct |
10 ms |
1664 KB |
Output is correct |
12 |
Correct |
10 ms |
1664 KB |
Output is correct |
13 |
Correct |
10 ms |
1664 KB |
Output is correct |
14 |
Correct |
9 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1408 KB |
Output is correct |
2 |
Correct |
10 ms |
1664 KB |
Output is correct |
3 |
Correct |
11 ms |
1664 KB |
Output is correct |
4 |
Correct |
9 ms |
1536 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
1152 KB |
Output is correct |
7 |
Correct |
6 ms |
1024 KB |
Output is correct |
8 |
Correct |
7 ms |
1024 KB |
Output is correct |
9 |
Correct |
6 ms |
1024 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
6 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1152 KB |
Output is correct |
2 |
Correct |
9 ms |
1152 KB |
Output is correct |
3 |
Correct |
6 ms |
1152 KB |
Output is correct |
4 |
Correct |
7 ms |
1152 KB |
Output is correct |
5 |
Correct |
6 ms |
1152 KB |
Output is correct |
6 |
Correct |
7 ms |
1152 KB |
Output is correct |
7 |
Correct |
6 ms |
1152 KB |
Output is correct |
8 |
Correct |
6 ms |
1152 KB |
Output is correct |
9 |
Correct |
7 ms |
1152 KB |
Output is correct |
10 |
Correct |
6 ms |
1152 KB |
Output is correct |
11 |
Correct |
5 ms |
1152 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Incorrect |
1 ms |
256 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
20 |
Halted |
0 ms |
0 KB |
- |