Submission #806742

# Submission time Handle Problem Language Result Execution time Memory
806742 2023-08-04T09:26:34 Z ymm Toy Train (IOI17_train) C++17
100 / 100
416 ms 2092 KB
%:include "train.h"
%:include <bits/stdc++.h>
%:define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
%:define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 5050;
bool rem[N];
bool owner[N];
bool charg[N];
vector<int> A[N], T[N];
vector<int> V;

void remove(const vector<int> &vec)
{
	for (int v : vec)
		rem[v] = 1;
	Loop (i,0,V.size()) {
		if (rem[V[i]]) {
			swap(V[i], V.back());
			V.pop_back();
			--i;
		}
	}
	for (auto *E : {A, T}) for (int v : V) {
		Loop (i,0,E[v].size()) {
			if (rem[E[v][i]]) {
				swap(E[v][i], E[v].back());
				E[v].pop_back();
				--i;
			}
		}
	}
}

int cnt[N];
bool vis[N];
void dfs(int v, bool o)
{
	vis[v] = 1;
	for (int u : T[v]) {
		++cnt[u];
		if (!vis[u] && (owner[u] == o || cnt[u] == A[u].size()))
			dfs(u, o);
	}
}
vector<int> f(const vector<int> &vec, bool o)
{
	for (int v : vec) {
		if (!rem[v] && !vis[v])
			dfs(v, o);
	}
	vector<int> ans;
	for (int v : V) {
		if (vis[v])
			ans.push_back(v);
		vis[v] = 0;
		cnt[v] = 0;
	}
	return ans;
}

vector<int> cmpl(const vector<int> &vec)
{
	vector<int> ans;
	static bool a[N];
	for (int v : vec)
		a[v] = 1;
	for (int v : V) {
		if (!a[v])
			ans.push_back(v);
	}
	for (int v : vec)
		a[v] = 0;
	return ans;
}

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> vv, std::vector<int> uu)
{
	int n = a.size();
	V.resize(n);
	iota(V.begin(), V.end(), 0);
	vector<int> charg;
	Loop (i,0,n) {
		owner[i] = a[i];
		if (r[i])
			charg.push_back(i);
	}
	Loop (i,0,vv.size()) {
		int v = vv[i], u = uu[i];
		A[v].push_back(u);
		T[u].push_back(v);
	}
	vector<int> ans;
	for (;;) {
		auto vec = f(charg, 1);
		if (vec.size() == V.size()) {
			ans = V;
			break;
		}
		if (vec.size() == 0)
			break;
		auto vec2 = f(cmpl(vec), 0);
		remove(vec2);
	}
	vector<int> res(n);
	for (int v : ans)
		res[v] = 1;
	return res;
}

Compilation message

train.cpp: In function 'void dfs(int, bool)':
train.cpp:46:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   if (!vis[u] && (owner[u] == o || cnt[u] == A[u].size()))
      |                                    ~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1236 KB Output is correct
2 Correct 4 ms 1240 KB Output is correct
3 Correct 4 ms 1204 KB Output is correct
4 Correct 4 ms 1232 KB Output is correct
5 Correct 4 ms 1204 KB Output is correct
6 Correct 4 ms 1204 KB Output is correct
7 Correct 5 ms 1204 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
10 Correct 3 ms 1108 KB Output is correct
11 Correct 4 ms 1200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 548 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 544 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 552 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 552 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 2092 KB Output is correct
2 Correct 147 ms 2088 KB Output is correct
3 Correct 182 ms 2076 KB Output is correct
4 Correct 7 ms 1876 KB Output is correct
5 Correct 7 ms 1840 KB Output is correct
6 Correct 7 ms 1620 KB Output is correct
7 Correct 6 ms 1620 KB Output is correct
8 Correct 6 ms 1612 KB Output is correct
9 Correct 5 ms 1620 KB Output is correct
10 Correct 6 ms 1612 KB Output is correct
11 Correct 6 ms 1604 KB Output is correct
12 Correct 6 ms 1492 KB Output is correct
13 Correct 6 ms 1876 KB Output is correct
14 Correct 6 ms 1840 KB Output is correct
15 Correct 6 ms 1876 KB Output is correct
16 Correct 6 ms 1876 KB Output is correct
17 Correct 6 ms 1848 KB Output is correct
18 Correct 239 ms 1532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1492 KB Output is correct
2 Correct 6 ms 1460 KB Output is correct
3 Correct 8 ms 1588 KB Output is correct
4 Correct 6 ms 1712 KB Output is correct
5 Correct 8 ms 1620 KB Output is correct
6 Correct 6 ms 1620 KB Output is correct
7 Correct 7 ms 1620 KB Output is correct
8 Correct 6 ms 1620 KB Output is correct
9 Correct 6 ms 1604 KB Output is correct
10 Correct 6 ms 1620 KB Output is correct
11 Correct 6 ms 1620 KB Output is correct
12 Correct 6 ms 1588 KB Output is correct
13 Correct 6 ms 1748 KB Output is correct
14 Correct 6 ms 1552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1748 KB Output is correct
2 Correct 6 ms 1748 KB Output is correct
3 Correct 6 ms 1620 KB Output is correct
4 Correct 6 ms 1620 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 4 ms 1108 KB Output is correct
7 Correct 4 ms 1236 KB Output is correct
8 Correct 5 ms 1320 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 5 ms 1204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1236 KB Output is correct
2 Correct 4 ms 1240 KB Output is correct
3 Correct 4 ms 1204 KB Output is correct
4 Correct 4 ms 1232 KB Output is correct
5 Correct 4 ms 1204 KB Output is correct
6 Correct 4 ms 1204 KB Output is correct
7 Correct 5 ms 1204 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
10 Correct 3 ms 1108 KB Output is correct
11 Correct 4 ms 1200 KB Output is correct
12 Correct 1 ms 548 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 544 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 552 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 552 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 548 KB Output is correct
32 Correct 82 ms 2092 KB Output is correct
33 Correct 147 ms 2088 KB Output is correct
34 Correct 182 ms 2076 KB Output is correct
35 Correct 7 ms 1876 KB Output is correct
36 Correct 7 ms 1840 KB Output is correct
37 Correct 7 ms 1620 KB Output is correct
38 Correct 6 ms 1620 KB Output is correct
39 Correct 6 ms 1612 KB Output is correct
40 Correct 5 ms 1620 KB Output is correct
41 Correct 6 ms 1612 KB Output is correct
42 Correct 6 ms 1604 KB Output is correct
43 Correct 6 ms 1492 KB Output is correct
44 Correct 6 ms 1876 KB Output is correct
45 Correct 6 ms 1840 KB Output is correct
46 Correct 6 ms 1876 KB Output is correct
47 Correct 6 ms 1876 KB Output is correct
48 Correct 6 ms 1848 KB Output is correct
49 Correct 239 ms 1532 KB Output is correct
50 Correct 6 ms 1492 KB Output is correct
51 Correct 6 ms 1460 KB Output is correct
52 Correct 8 ms 1588 KB Output is correct
53 Correct 6 ms 1712 KB Output is correct
54 Correct 8 ms 1620 KB Output is correct
55 Correct 6 ms 1620 KB Output is correct
56 Correct 7 ms 1620 KB Output is correct
57 Correct 6 ms 1620 KB Output is correct
58 Correct 6 ms 1604 KB Output is correct
59 Correct 6 ms 1620 KB Output is correct
60 Correct 6 ms 1620 KB Output is correct
61 Correct 6 ms 1588 KB Output is correct
62 Correct 6 ms 1748 KB Output is correct
63 Correct 6 ms 1552 KB Output is correct
64 Correct 6 ms 1748 KB Output is correct
65 Correct 6 ms 1748 KB Output is correct
66 Correct 6 ms 1620 KB Output is correct
67 Correct 6 ms 1620 KB Output is correct
68 Correct 2 ms 596 KB Output is correct
69 Correct 4 ms 1108 KB Output is correct
70 Correct 4 ms 1236 KB Output is correct
71 Correct 5 ms 1320 KB Output is correct
72 Correct 5 ms 1236 KB Output is correct
73 Correct 2 ms 724 KB Output is correct
74 Correct 5 ms 1204 KB Output is correct
75 Correct 115 ms 1808 KB Output is correct
76 Correct 159 ms 2008 KB Output is correct
77 Correct 210 ms 2004 KB Output is correct
78 Correct 206 ms 2068 KB Output is correct
79 Correct 200 ms 2004 KB Output is correct
80 Correct 7 ms 1748 KB Output is correct
81 Correct 6 ms 1620 KB Output is correct
82 Correct 7 ms 1620 KB Output is correct
83 Correct 8 ms 1748 KB Output is correct
84 Correct 8 ms 1748 KB Output is correct
85 Correct 9 ms 1620 KB Output is correct
86 Correct 8 ms 1712 KB Output is correct
87 Correct 8 ms 1620 KB Output is correct
88 Correct 13 ms 1620 KB Output is correct
89 Correct 7 ms 1688 KB Output is correct
90 Correct 15 ms 1588 KB Output is correct
91 Correct 11 ms 1620 KB Output is correct
92 Correct 19 ms 1748 KB Output is correct
93 Correct 18 ms 1680 KB Output is correct
94 Correct 18 ms 1696 KB Output is correct
95 Correct 20 ms 1620 KB Output is correct
96 Correct 68 ms 1592 KB Output is correct
97 Correct 272 ms 1684 KB Output is correct
98 Correct 394 ms 1644 KB Output is correct
99 Correct 416 ms 1616 KB Output is correct
100 Correct 214 ms 1536 KB Output is correct