# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
45493 |
2018-04-14T12:21:50 Z |
Abelyan |
Toy Train (IOI17_train) |
C++17 |
|
2000 ms |
1920 KB |
#include "train.h"
#include <algorithm>
#include <vector>
#include <unordered_set>
#include <queue>
using namespace std;
const int N = 5006;
int n, m;
vector<int> g[N],ing[N];
bool col[N],chrg[N];
void rev(vector<bool> &s, vector<bool> &ans){
for (int i = 0; i < n; i++){
ans[i] = !s[i];
}
}
void Fw(int w, const vector<bool> &s, vector<bool> &ans){
static queue<int> q;
ans.resize(0);
for (int i = 0; i < s.size(); i++){
ans.push_back(s[i]);
if (s[i])
q.push(i);
}
while (!q.empty()){
int v = q.front();
q.pop();
for (auto to : ing[v]){
if (ans[to]) continue;
bool mb = true;
for (auto k : g[to]){
mb &= ans[k] == true;
}
if (col[to] == w || mb){
ans[to] = true;
q.push(to);
}
}
}
}
void intersect(const vector<bool> &a, const vector<bool> &b, vector<bool> &ans){
ans.resize(0);
for (int i = 0; i < a.size();i++){
ans.push_back(b[i] && a[i]);
}
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = a.size();
m = u.size();
for (int i = 0; i < m; i++){
g[u[i]].push_back(v[i]);
ing[v[i]].push_back(u[i]);
}
for (int i = 0; i < n; i++){
if (a[i]){
col[i] = true;
}
}
for (int i = 0; i < n; i++){
if (r[i]) chrg[i] = true;
}
while (1){
static vector<bool> R(n);
for (int i = 0; i < n; i++){
R[i] = chrg[i];
}
static vector<bool> far(n), gg(n) , x(n), ht(n);
Fw(1, R, far);
rev(far, gg);
Fw(0, gg, x);
intersect(far, x, ht);
bool mb = false;
for (int i = 0; i < ht.size();i++){
if (ht[i] && chrg[i]) mb = true, chrg[i] = false;
}
if (!mb){
vector<int> ans(n,1);
for (int i = 0; i < x.size();i++){
if (x[i])
ans[i] = 0;
}
return ans;
}
}
}
/*
2 4
0 1
1 0
0 0
0 1
1 0
1 1
*/
Compilation message
train.cpp: In function 'void Fw(int, const std::vector<bool>&, std::vector<bool>&)':
train.cpp:22:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size(); i++){
~~^~~~~~~~~~
train.cpp: In function 'void intersect(const std::vector<bool>&, const std::vector<bool>&, std::vector<bool>&)':
train.cpp:46:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < a.size();i++){
~~^~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:78:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ht.size();i++){
~~^~~~~~~~~~~
train.cpp:83:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < x.size();i++){
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1016 KB |
Output is correct |
2 |
Correct |
9 ms |
1124 KB |
Output is correct |
3 |
Correct |
8 ms |
1216 KB |
Output is correct |
4 |
Correct |
9 ms |
1308 KB |
Output is correct |
5 |
Correct |
8 ms |
1308 KB |
Output is correct |
6 |
Correct |
8 ms |
1308 KB |
Output is correct |
7 |
Correct |
7 ms |
1488 KB |
Output is correct |
8 |
Correct |
12 ms |
1488 KB |
Output is correct |
9 |
Correct |
7 ms |
1488 KB |
Output is correct |
10 |
Correct |
7 ms |
1488 KB |
Output is correct |
11 |
Correct |
9 ms |
1488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1488 KB |
Output is correct |
2 |
Correct |
2 ms |
1488 KB |
Output is correct |
3 |
Correct |
2 ms |
1488 KB |
Output is correct |
4 |
Correct |
2 ms |
1488 KB |
Output is correct |
5 |
Correct |
2 ms |
1488 KB |
Output is correct |
6 |
Correct |
2 ms |
1488 KB |
Output is correct |
7 |
Correct |
2 ms |
1488 KB |
Output is correct |
8 |
Correct |
2 ms |
1488 KB |
Output is correct |
9 |
Correct |
2 ms |
1488 KB |
Output is correct |
10 |
Correct |
2 ms |
1488 KB |
Output is correct |
11 |
Correct |
2 ms |
1488 KB |
Output is correct |
12 |
Correct |
3 ms |
1488 KB |
Output is correct |
13 |
Correct |
2 ms |
1488 KB |
Output is correct |
14 |
Correct |
2 ms |
1488 KB |
Output is correct |
15 |
Correct |
2 ms |
1488 KB |
Output is correct |
16 |
Correct |
2 ms |
1488 KB |
Output is correct |
17 |
Correct |
2 ms |
1488 KB |
Output is correct |
18 |
Correct |
2 ms |
1488 KB |
Output is correct |
19 |
Correct |
2 ms |
1488 KB |
Output is correct |
20 |
Correct |
2 ms |
1488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
166 ms |
1920 KB |
Output is correct |
2 |
Correct |
366 ms |
1920 KB |
Output is correct |
3 |
Correct |
488 ms |
1920 KB |
Output is correct |
4 |
Correct |
12 ms |
1920 KB |
Output is correct |
5 |
Correct |
13 ms |
1920 KB |
Output is correct |
6 |
Correct |
16 ms |
1920 KB |
Output is correct |
7 |
Correct |
11 ms |
1920 KB |
Output is correct |
8 |
Correct |
11 ms |
1920 KB |
Output is correct |
9 |
Correct |
18 ms |
1920 KB |
Output is correct |
10 |
Correct |
10 ms |
1920 KB |
Output is correct |
11 |
Correct |
18 ms |
1920 KB |
Output is correct |
12 |
Correct |
18 ms |
1920 KB |
Output is correct |
13 |
Correct |
11 ms |
1920 KB |
Output is correct |
14 |
Correct |
13 ms |
1920 KB |
Output is correct |
15 |
Correct |
13 ms |
1920 KB |
Output is correct |
16 |
Correct |
12 ms |
1920 KB |
Output is correct |
17 |
Correct |
11 ms |
1920 KB |
Output is correct |
18 |
Correct |
730 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1920 KB |
Output is correct |
2 |
Correct |
12 ms |
1920 KB |
Output is correct |
3 |
Correct |
11 ms |
1920 KB |
Output is correct |
4 |
Correct |
19 ms |
1920 KB |
Output is correct |
5 |
Correct |
12 ms |
1920 KB |
Output is correct |
6 |
Correct |
16 ms |
1920 KB |
Output is correct |
7 |
Correct |
12 ms |
1920 KB |
Output is correct |
8 |
Correct |
11 ms |
1920 KB |
Output is correct |
9 |
Correct |
12 ms |
1920 KB |
Output is correct |
10 |
Correct |
11 ms |
1920 KB |
Output is correct |
11 |
Correct |
12 ms |
1920 KB |
Output is correct |
12 |
Correct |
19 ms |
1920 KB |
Output is correct |
13 |
Correct |
12 ms |
1920 KB |
Output is correct |
14 |
Correct |
11 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
1920 KB |
Output is correct |
2 |
Correct |
11 ms |
1920 KB |
Output is correct |
3 |
Correct |
19 ms |
1920 KB |
Output is correct |
4 |
Correct |
11 ms |
1920 KB |
Output is correct |
5 |
Correct |
2 ms |
1920 KB |
Output is correct |
6 |
Correct |
6 ms |
1920 KB |
Output is correct |
7 |
Correct |
12 ms |
1920 KB |
Output is correct |
8 |
Correct |
8 ms |
1920 KB |
Output is correct |
9 |
Correct |
8 ms |
1920 KB |
Output is correct |
10 |
Correct |
4 ms |
1920 KB |
Output is correct |
11 |
Correct |
9 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1016 KB |
Output is correct |
2 |
Correct |
9 ms |
1124 KB |
Output is correct |
3 |
Correct |
8 ms |
1216 KB |
Output is correct |
4 |
Correct |
9 ms |
1308 KB |
Output is correct |
5 |
Correct |
8 ms |
1308 KB |
Output is correct |
6 |
Correct |
8 ms |
1308 KB |
Output is correct |
7 |
Correct |
7 ms |
1488 KB |
Output is correct |
8 |
Correct |
12 ms |
1488 KB |
Output is correct |
9 |
Correct |
7 ms |
1488 KB |
Output is correct |
10 |
Correct |
7 ms |
1488 KB |
Output is correct |
11 |
Correct |
9 ms |
1488 KB |
Output is correct |
12 |
Correct |
2 ms |
1488 KB |
Output is correct |
13 |
Correct |
2 ms |
1488 KB |
Output is correct |
14 |
Correct |
2 ms |
1488 KB |
Output is correct |
15 |
Correct |
2 ms |
1488 KB |
Output is correct |
16 |
Correct |
2 ms |
1488 KB |
Output is correct |
17 |
Correct |
2 ms |
1488 KB |
Output is correct |
18 |
Correct |
2 ms |
1488 KB |
Output is correct |
19 |
Correct |
2 ms |
1488 KB |
Output is correct |
20 |
Correct |
2 ms |
1488 KB |
Output is correct |
21 |
Correct |
2 ms |
1488 KB |
Output is correct |
22 |
Correct |
2 ms |
1488 KB |
Output is correct |
23 |
Correct |
3 ms |
1488 KB |
Output is correct |
24 |
Correct |
2 ms |
1488 KB |
Output is correct |
25 |
Correct |
2 ms |
1488 KB |
Output is correct |
26 |
Correct |
2 ms |
1488 KB |
Output is correct |
27 |
Correct |
2 ms |
1488 KB |
Output is correct |
28 |
Correct |
2 ms |
1488 KB |
Output is correct |
29 |
Correct |
2 ms |
1488 KB |
Output is correct |
30 |
Correct |
2 ms |
1488 KB |
Output is correct |
31 |
Correct |
2 ms |
1488 KB |
Output is correct |
32 |
Correct |
166 ms |
1920 KB |
Output is correct |
33 |
Correct |
366 ms |
1920 KB |
Output is correct |
34 |
Correct |
488 ms |
1920 KB |
Output is correct |
35 |
Correct |
12 ms |
1920 KB |
Output is correct |
36 |
Correct |
13 ms |
1920 KB |
Output is correct |
37 |
Correct |
16 ms |
1920 KB |
Output is correct |
38 |
Correct |
11 ms |
1920 KB |
Output is correct |
39 |
Correct |
11 ms |
1920 KB |
Output is correct |
40 |
Correct |
18 ms |
1920 KB |
Output is correct |
41 |
Correct |
10 ms |
1920 KB |
Output is correct |
42 |
Correct |
18 ms |
1920 KB |
Output is correct |
43 |
Correct |
18 ms |
1920 KB |
Output is correct |
44 |
Correct |
11 ms |
1920 KB |
Output is correct |
45 |
Correct |
13 ms |
1920 KB |
Output is correct |
46 |
Correct |
13 ms |
1920 KB |
Output is correct |
47 |
Correct |
12 ms |
1920 KB |
Output is correct |
48 |
Correct |
11 ms |
1920 KB |
Output is correct |
49 |
Correct |
730 ms |
1920 KB |
Output is correct |
50 |
Correct |
17 ms |
1920 KB |
Output is correct |
51 |
Correct |
12 ms |
1920 KB |
Output is correct |
52 |
Correct |
11 ms |
1920 KB |
Output is correct |
53 |
Correct |
19 ms |
1920 KB |
Output is correct |
54 |
Correct |
12 ms |
1920 KB |
Output is correct |
55 |
Correct |
16 ms |
1920 KB |
Output is correct |
56 |
Correct |
12 ms |
1920 KB |
Output is correct |
57 |
Correct |
11 ms |
1920 KB |
Output is correct |
58 |
Correct |
12 ms |
1920 KB |
Output is correct |
59 |
Correct |
11 ms |
1920 KB |
Output is correct |
60 |
Correct |
12 ms |
1920 KB |
Output is correct |
61 |
Correct |
19 ms |
1920 KB |
Output is correct |
62 |
Correct |
12 ms |
1920 KB |
Output is correct |
63 |
Correct |
11 ms |
1920 KB |
Output is correct |
64 |
Correct |
16 ms |
1920 KB |
Output is correct |
65 |
Correct |
11 ms |
1920 KB |
Output is correct |
66 |
Correct |
19 ms |
1920 KB |
Output is correct |
67 |
Correct |
11 ms |
1920 KB |
Output is correct |
68 |
Correct |
2 ms |
1920 KB |
Output is correct |
69 |
Correct |
6 ms |
1920 KB |
Output is correct |
70 |
Correct |
12 ms |
1920 KB |
Output is correct |
71 |
Correct |
8 ms |
1920 KB |
Output is correct |
72 |
Correct |
8 ms |
1920 KB |
Output is correct |
73 |
Correct |
4 ms |
1920 KB |
Output is correct |
74 |
Correct |
9 ms |
1920 KB |
Output is correct |
75 |
Execution timed out |
2041 ms |
1920 KB |
Time limit exceeded |
76 |
Halted |
0 ms |
0 KB |
- |