# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
289121 |
2020-09-02T11:25:58 Z |
_7_7_ |
Toy Train (IOI17_train) |
C++14 |
|
620 ms |
2048 KB |
#include "train.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 5012;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;
int n, cnt[N], m, ok, a[N], r[N], v[N*5], u[N*5];
bool was[N], was1[N];
queue < int > q;
vi g[N], gr[N];
vi who_wins(vi A, vi R, vi U, vi V) {
n = sz(A);
m = sz(V);
for (int i = 0; i < n; ++i) {
a[i] = A[i];
r[i] = R[i];
}
for (int i = 0; i < m; ++i) {
v[i] = V[i];
u[i] = U[i];
}
for (int i = 0; i < m; ++i) {
g[u[i]].pb(v[i]);
gr[v[i]].pb(u[i]);
}
bool run;
do {
run = 0;
for (int i = 0; i < n; ++i) {
was1[i] = 0;
if (!was[i] && r[i]) {
q.push(i);
was1[i] = 1;
}
cnt[i] = !a[i] ? sz(g[i]) : 1;
}
while (sz(q)) {
int v = q.front();
q.pop();
for (auto to : gr[v]) {
--cnt[to];
// cerr << to << endl;
if (!was[to] && !was1[to] && !cnt[to]) {
q.push(to);
was1[to] = 1;
}
}
}
for (int i = 0; i < n; ++i) {
if (!was1[i] && !was[i]) {
q.push(i);
was[i] = 1;
}
cnt[i] = a[i] ? sz(g[i]) : 1;
}
while (sz(q)) {
run = 1;
int v = q.front();
q.pop();
for (auto to : gr[v]) {
--cnt[to];
if (!was[to] && !cnt[to]) {
q.push(to);
was[to] = 1;
}
}
}
for (int i = 0; i < n; ++i)
if (!was[i])
for (int j = 0; j < sz(g[i]); ++j)
if (was[g[i][j]]) {
swap(g[i][j], g[i].back());
g[i].ppb();
--j;
}
} while (run);
vi ans;
for (int i = 0; i < n; ++i)
ans.pb(was[i]^1);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1280 KB |
Output is correct |
2 |
Correct |
7 ms |
1280 KB |
Output is correct |
3 |
Correct |
7 ms |
1280 KB |
Output is correct |
4 |
Correct |
7 ms |
1280 KB |
Output is correct |
5 |
Correct |
7 ms |
1280 KB |
Output is correct |
6 |
Correct |
6 ms |
1280 KB |
Output is correct |
7 |
Correct |
6 ms |
1280 KB |
Output is correct |
8 |
Correct |
6 ms |
1280 KB |
Output is correct |
9 |
Correct |
7 ms |
1280 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 |
640 KB |
Output is correct |
2 |
Correct |
1 ms |
640 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
640 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
1 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
640 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
640 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
640 KB |
Output is correct |
19 |
Correct |
1 ms |
640 KB |
Output is correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
1784 KB |
Output is correct |
2 |
Correct |
270 ms |
1784 KB |
Output is correct |
3 |
Correct |
360 ms |
1664 KB |
Output is correct |
4 |
Correct |
11 ms |
1664 KB |
Output is correct |
5 |
Correct |
12 ms |
1920 KB |
Output is correct |
6 |
Correct |
11 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 |
10 ms |
1792 KB |
Output is correct |
10 |
Correct |
11 ms |
1792 KB |
Output is correct |
11 |
Correct |
10 ms |
1792 KB |
Output is correct |
12 |
Correct |
9 ms |
1792 KB |
Output is correct |
13 |
Correct |
11 ms |
1920 KB |
Output is correct |
14 |
Correct |
11 ms |
1920 KB |
Output is correct |
15 |
Correct |
10 ms |
1920 KB |
Output is correct |
16 |
Correct |
12 ms |
1920 KB |
Output is correct |
17 |
Correct |
10 ms |
1920 KB |
Output is correct |
18 |
Correct |
440 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1408 KB |
Output is correct |
2 |
Correct |
10 ms |
1664 KB |
Output is correct |
3 |
Correct |
10 ms |
1920 KB |
Output is correct |
4 |
Correct |
11 ms |
1824 KB |
Output is correct |
5 |
Correct |
12 ms |
1920 KB |
Output is correct |
6 |
Correct |
11 ms |
1792 KB |
Output is correct |
7 |
Correct |
10 ms |
1792 KB |
Output is correct |
8 |
Correct |
10 ms |
1792 KB |
Output is correct |
9 |
Correct |
10 ms |
1792 KB |
Output is correct |
10 |
Correct |
11 ms |
1920 KB |
Output is correct |
11 |
Correct |
11 ms |
1920 KB |
Output is correct |
12 |
Correct |
11 ms |
1920 KB |
Output is correct |
13 |
Correct |
11 ms |
1920 KB |
Output is correct |
14 |
Correct |
10 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1664 KB |
Output is correct |
2 |
Correct |
11 ms |
1920 KB |
Output is correct |
3 |
Correct |
11 ms |
1920 KB |
Output is correct |
4 |
Correct |
10 ms |
1792 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
1280 KB |
Output is correct |
7 |
Correct |
7 ms |
1408 KB |
Output is correct |
8 |
Correct |
8 ms |
1536 KB |
Output is correct |
9 |
Correct |
7 ms |
1408 KB |
Output is correct |
10 |
Correct |
2 ms |
884 KB |
Output is correct |
11 |
Correct |
10 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1280 KB |
Output is correct |
2 |
Correct |
7 ms |
1280 KB |
Output is correct |
3 |
Correct |
7 ms |
1280 KB |
Output is correct |
4 |
Correct |
7 ms |
1280 KB |
Output is correct |
5 |
Correct |
7 ms |
1280 KB |
Output is correct |
6 |
Correct |
6 ms |
1280 KB |
Output is correct |
7 |
Correct |
6 ms |
1280 KB |
Output is correct |
8 |
Correct |
6 ms |
1280 KB |
Output is correct |
9 |
Correct |
7 ms |
1280 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 |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
640 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
640 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
640 KB |
Output is correct |
19 |
Correct |
1 ms |
640 KB |
Output is correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
21 |
Correct |
1 ms |
640 KB |
Output is correct |
22 |
Correct |
1 ms |
640 KB |
Output is correct |
23 |
Correct |
1 ms |
640 KB |
Output is correct |
24 |
Correct |
1 ms |
640 KB |
Output is correct |
25 |
Correct |
1 ms |
640 KB |
Output is correct |
26 |
Correct |
1 ms |
640 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
640 KB |
Output is correct |
29 |
Correct |
1 ms |
640 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
1 ms |
640 KB |
Output is correct |
32 |
Correct |
138 ms |
1784 KB |
Output is correct |
33 |
Correct |
270 ms |
1784 KB |
Output is correct |
34 |
Correct |
360 ms |
1664 KB |
Output is correct |
35 |
Correct |
11 ms |
1664 KB |
Output is correct |
36 |
Correct |
12 ms |
1920 KB |
Output is correct |
37 |
Correct |
11 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 |
10 ms |
1792 KB |
Output is correct |
41 |
Correct |
11 ms |
1792 KB |
Output is correct |
42 |
Correct |
10 ms |
1792 KB |
Output is correct |
43 |
Correct |
9 ms |
1792 KB |
Output is correct |
44 |
Correct |
11 ms |
1920 KB |
Output is correct |
45 |
Correct |
11 ms |
1920 KB |
Output is correct |
46 |
Correct |
10 ms |
1920 KB |
Output is correct |
47 |
Correct |
12 ms |
1920 KB |
Output is correct |
48 |
Correct |
10 ms |
1920 KB |
Output is correct |
49 |
Correct |
440 ms |
1408 KB |
Output is correct |
50 |
Correct |
9 ms |
1408 KB |
Output is correct |
51 |
Correct |
10 ms |
1664 KB |
Output is correct |
52 |
Correct |
10 ms |
1920 KB |
Output is correct |
53 |
Correct |
11 ms |
1824 KB |
Output is correct |
54 |
Correct |
12 ms |
1920 KB |
Output is correct |
55 |
Correct |
11 ms |
1792 KB |
Output is correct |
56 |
Correct |
10 ms |
1792 KB |
Output is correct |
57 |
Correct |
10 ms |
1792 KB |
Output is correct |
58 |
Correct |
10 ms |
1792 KB |
Output is correct |
59 |
Correct |
11 ms |
1920 KB |
Output is correct |
60 |
Correct |
11 ms |
1920 KB |
Output is correct |
61 |
Correct |
11 ms |
1920 KB |
Output is correct |
62 |
Correct |
11 ms |
1920 KB |
Output is correct |
63 |
Correct |
10 ms |
1792 KB |
Output is correct |
64 |
Correct |
11 ms |
1664 KB |
Output is correct |
65 |
Correct |
11 ms |
1920 KB |
Output is correct |
66 |
Correct |
11 ms |
1920 KB |
Output is correct |
67 |
Correct |
10 ms |
1792 KB |
Output is correct |
68 |
Correct |
1 ms |
640 KB |
Output is correct |
69 |
Correct |
5 ms |
1280 KB |
Output is correct |
70 |
Correct |
7 ms |
1408 KB |
Output is correct |
71 |
Correct |
8 ms |
1536 KB |
Output is correct |
72 |
Correct |
7 ms |
1408 KB |
Output is correct |
73 |
Correct |
2 ms |
884 KB |
Output is correct |
74 |
Correct |
10 ms |
1408 KB |
Output is correct |
75 |
Correct |
178 ms |
1912 KB |
Output is correct |
76 |
Correct |
289 ms |
1912 KB |
Output is correct |
77 |
Correct |
397 ms |
1912 KB |
Output is correct |
78 |
Correct |
399 ms |
1916 KB |
Output is correct |
79 |
Correct |
399 ms |
1912 KB |
Output is correct |
80 |
Correct |
11 ms |
1920 KB |
Output is correct |
81 |
Correct |
11 ms |
1920 KB |
Output is correct |
82 |
Correct |
12 ms |
1920 KB |
Output is correct |
83 |
Correct |
13 ms |
2048 KB |
Output is correct |
84 |
Correct |
12 ms |
1920 KB |
Output is correct |
85 |
Correct |
11 ms |
1920 KB |
Output is correct |
86 |
Correct |
14 ms |
1920 KB |
Output is correct |
87 |
Correct |
11 ms |
1920 KB |
Output is correct |
88 |
Correct |
15 ms |
1920 KB |
Output is correct |
89 |
Correct |
12 ms |
1920 KB |
Output is correct |
90 |
Correct |
19 ms |
1920 KB |
Output is correct |
91 |
Correct |
17 ms |
1920 KB |
Output is correct |
92 |
Correct |
28 ms |
1912 KB |
Output is correct |
93 |
Correct |
28 ms |
1920 KB |
Output is correct |
94 |
Correct |
30 ms |
1920 KB |
Output is correct |
95 |
Correct |
31 ms |
1912 KB |
Output is correct |
96 |
Correct |
90 ms |
1784 KB |
Output is correct |
97 |
Correct |
357 ms |
1912 KB |
Output is correct |
98 |
Correct |
604 ms |
1912 KB |
Output is correct |
99 |
Correct |
620 ms |
1912 KB |
Output is correct |
100 |
Correct |
450 ms |
1528 KB |
Output is correct |