# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
561783 |
2022-05-13T13:32:01 Z |
raid |
Toy Train (IOI17_train) |
C++17 |
|
199 ms |
1740 KB |
#include <bits/stdc++.h>
#include "train.h"
using namespace std;
const int MAXN = 5005;
vector<int> G[MAXN], Gt[MAXN], owner, fuel;
vector<int> res, S;
vector<int> inset;
int N;
vector<int> who_wins( vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
owner = a, fuel = r;
for ( int i = 0; i < (int)u.size(); ++i ) {
G[u[i]].push_back(v[i]);
Gt[v[i]].push_back(u[i]);
}
N = a.size();
res.resize(N), S.resize(N);
queue<int> q;
inset.resize(N);
for ( int i = 0; i < N; ++i ) inset[i] = 1;
bool emp = false;
while ( !emp ) {
for ( int i = 0; i < N; ++i ) {
if ( fuel[i] && inset[i] ) {
q.push(i);
S[i] = 1;
} else {
S[i] = 0;
}
}
while ( !q.empty() ) {
int u = q.front();
q.pop();
for ( auto v : Gt[u] ) {
if ( inset[v] && !S[v] && owner[v] == 1 ) {
q.push(v);
S[v] = 1;
} else if ( inset[v] && !S[v] && owner[v] == 0 ) {
bool ok = true;
for ( auto vv : G[v] ) {
ok &= S[vv];
}
if ( ok ) {
q.push(v);
S[v] = 1;
}
}
}
}
bool ok = true;
for ( int i = 0; i < N; ++i ) {
if ( S[i] == 0 && inset[i] ) {
ok = false;
}
}
if ( ok ) {
for ( int i = 0; i < N; ++i ) {
res[i] = S[i];
}
break;
}
for ( int i = 0; i < N; ++i ) {
if ( inset[i] ) {
S[i] = 1 - S[i];
if ( S[i] ) q.push(i);
}
}
while ( !q.empty() ) {
int u = q.front();
q.pop();
for ( auto v : Gt[u] ) {
if ( inset[v] && !S[v] && owner[v] == 0 ) {
q.push(v);
S[v] = 1;
} else if ( inset[v] && !S[v] && owner[v] == 1 ) {
bool ok = true;
for ( auto vv : G[v] ) {
ok &= S[vv];
}
if ( ok ) {
q.push(v);
S[v] = 1;
}
}
}
}
for ( int i = 0; i < N; ++i ) {
if ( S[i] ) inset[i] = 0;
}
}
return res;
}
/*
int main() {
int n, m;
assert(2 == scanf("%d %d", &n, &m));
vector<int> a(n), r(n), u(m), v(m);
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &a[i]));
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &r[i]));
for(int i = 0; i < m; i++)
scanf("%d", &u[i]);
for ( int i = 0; i < m; ++i ) {
scanf("%d", &v[i]);
}
vector<int> res = who_wins(a, r, u, v);
for(int i = 0; i < (int)res.size(); i++)
printf(i ? " %d" : "%d", res[i]);
printf("\n");
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1236 KB |
Output is correct |
2 |
Correct |
6 ms |
1224 KB |
Output is correct |
3 |
Correct |
6 ms |
1236 KB |
Output is correct |
4 |
Correct |
5 ms |
1236 KB |
Output is correct |
5 |
Correct |
5 ms |
1236 KB |
Output is correct |
6 |
Correct |
5 ms |
1236 KB |
Output is correct |
7 |
Correct |
4 ms |
1236 KB |
Output is correct |
8 |
Correct |
5 ms |
1192 KB |
Output is correct |
9 |
Correct |
5 ms |
1108 KB |
Output is correct |
10 |
Correct |
4 ms |
1108 KB |
Output is correct |
11 |
Correct |
4 ms |
1192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
536 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
536 KB |
Output is correct |
8 |
Incorrect |
1 ms |
540 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 |
80 ms |
1696 KB |
Output is correct |
2 |
Correct |
161 ms |
1680 KB |
Output is correct |
3 |
Correct |
199 ms |
1740 KB |
Output is correct |
4 |
Correct |
7 ms |
1652 KB |
Output is correct |
5 |
Incorrect |
8 ms |
1576 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 |
6 ms |
1492 KB |
Output is correct |
2 |
Correct |
8 ms |
1528 KB |
Output is correct |
3 |
Correct |
8 ms |
1620 KB |
Output is correct |
4 |
Correct |
8 ms |
1612 KB |
Output is correct |
5 |
Correct |
8 ms |
1576 KB |
Output is correct |
6 |
Correct |
9 ms |
1580 KB |
Output is correct |
7 |
Correct |
9 ms |
1620 KB |
Output is correct |
8 |
Correct |
8 ms |
1620 KB |
Output is correct |
9 |
Correct |
8 ms |
1564 KB |
Output is correct |
10 |
Correct |
8 ms |
1620 KB |
Output is correct |
11 |
Correct |
8 ms |
1608 KB |
Output is correct |
12 |
Correct |
8 ms |
1708 KB |
Output is correct |
13 |
Correct |
9 ms |
1608 KB |
Output is correct |
14 |
Correct |
8 ms |
1572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1576 KB |
Output is correct |
2 |
Correct |
7 ms |
1704 KB |
Output is correct |
3 |
Correct |
8 ms |
1576 KB |
Output is correct |
4 |
Correct |
8 ms |
1576 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
5 ms |
1192 KB |
Output is correct |
7 |
Correct |
6 ms |
1236 KB |
Output is correct |
8 |
Correct |
6 ms |
1236 KB |
Output is correct |
9 |
Correct |
5 ms |
1184 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
6 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1236 KB |
Output is correct |
2 |
Correct |
6 ms |
1224 KB |
Output is correct |
3 |
Correct |
6 ms |
1236 KB |
Output is correct |
4 |
Correct |
5 ms |
1236 KB |
Output is correct |
5 |
Correct |
5 ms |
1236 KB |
Output is correct |
6 |
Correct |
5 ms |
1236 KB |
Output is correct |
7 |
Correct |
4 ms |
1236 KB |
Output is correct |
8 |
Correct |
5 ms |
1192 KB |
Output is correct |
9 |
Correct |
5 ms |
1108 KB |
Output is correct |
10 |
Correct |
4 ms |
1108 KB |
Output is correct |
11 |
Correct |
4 ms |
1192 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
536 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
536 KB |
Output is correct |
19 |
Incorrect |
1 ms |
540 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
20 |
Halted |
0 ms |
0 KB |
- |