Submission #970362

# Submission time Handle Problem Language Result Execution time Memory
970362 2024-04-26T12:20:15 Z Itamar Toy Train (IOI17_train) C++14
100 / 100
1820 ms 1616 KB
#include "train.h"
#include <vector>
using namespace std;
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#include <algorithm>
#define x first
#define y second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vb vector<bool>
int n, m;
const int siz = 5e3 + 1;
vi fr[siz];
vi invf[siz];
#include <queue>
void func(vi& bad, vi& A) {
	vector<bool> vis(n);
	queue<int> q;
	for (int i = 0; i < n; i++)if (bad[i])q.push(i);
	vi deg(n); for (int i = 0; i < n; i++)deg[i] = fr[i].size();
	while (!q.empty()) {
		int i = q.front();
		q.pop();
		if (vis[i])continue;
		vis[i] = 1;
		bad[i] = 1;
		for (int f : invf[i]) {
			deg[f]--;
			if (A[f] == 1) {
				if (deg[f] == fr[f].size() - 1)q.push(f);
			}
			else {
				if (deg[f] == 0)q.push(f);
			}
		}
	}
}

vi who_wins(vi A, vi R, vi U, vi V) {
	n = R.size(), m = U.size();
	for (int i = 0; i < m; i++) {
		fr[U[i]].push_back(V[i]);
		invf[V[i]].push_back(U[i]);
	}
	vi bad(n,1);
	for (int it = 0; it <= n; it++) {
		vi badt(n);
		for (int i = 0; i < n; i++) {
			//if (bad[i]) {
			if (A[i]) {
				bool g = 0;
				for (int j : fr[i])if (bad[j])g = 1;
				if (g == 0)badt[i] = 0;
				else badt[i] = 1;
			}
			else {
				for (int j : fr[i]) {
					if (bad[j] == 0) {
						badt[i] = 0;
						break;
					}
					if (j == fr[i].back())badt[i] = 1;
				}
			}
			//}
		}
		bad = badt;

		vi badtt = R; for (int i = 0; i < n; i++)if (bad[i] == 0)badtt[i] = 0;
		func(badtt, A);
		for (int i = 0; i < n; i++)if (badtt[i] == 0)bad[i] = 0;
	}
	return bad;
}

Compilation message

train.cpp: In function 'void func(std::vector<int>&, std::vector<int>&)':
train.cpp:32:16: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     if (deg[f] == fr[f].size() - 1)q.push(f);
# Verdict Execution time Memory Grader output
1 Correct 691 ms 1216 KB Output is correct
2 Correct 671 ms 1220 KB Output is correct
3 Correct 702 ms 1224 KB Output is correct
4 Correct 670 ms 1220 KB Output is correct
5 Correct 691 ms 1216 KB Output is correct
6 Correct 758 ms 1220 KB Output is correct
7 Correct 227 ms 1212 KB Output is correct
8 Correct 744 ms 1120 KB Output is correct
9 Correct 753 ms 1196 KB Output is correct
10 Correct 799 ms 1180 KB Output is correct
11 Correct 837 ms 1196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 660 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 272 ms 1576 KB Output is correct
2 Correct 344 ms 1572 KB Output is correct
3 Correct 390 ms 1568 KB Output is correct
4 Correct 1266 ms 1548 KB Output is correct
5 Correct 1155 ms 1548 KB Output is correct
6 Correct 351 ms 1524 KB Output is correct
7 Correct 1567 ms 1528 KB Output is correct
8 Correct 970 ms 1516 KB Output is correct
9 Correct 275 ms 1492 KB Output is correct
10 Correct 1169 ms 1492 KB Output is correct
11 Correct 1087 ms 1472 KB Output is correct
12 Correct 318 ms 1432 KB Output is correct
13 Correct 1332 ms 1532 KB Output is correct
14 Correct 1330 ms 1532 KB Output is correct
15 Correct 1338 ms 1532 KB Output is correct
16 Correct 1341 ms 1536 KB Output is correct
17 Correct 1320 ms 1536 KB Output is correct
18 Correct 364 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1220 ms 1376 KB Output is correct
2 Correct 1214 ms 1424 KB Output is correct
3 Correct 211 ms 1504 KB Output is correct
4 Correct 145 ms 1372 KB Output is correct
5 Correct 1090 ms 1520 KB Output is correct
6 Correct 1338 ms 1504 KB Output is correct
7 Correct 1311 ms 1500 KB Output is correct
8 Correct 180 ms 1480 KB Output is correct
9 Correct 1322 ms 1460 KB Output is correct
10 Correct 1415 ms 1540 KB Output is correct
11 Correct 1338 ms 1544 KB Output is correct
12 Correct 1477 ms 1536 KB Output is correct
13 Correct 1173 ms 1536 KB Output is correct
14 Correct 1269 ms 1448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1372 ms 1548 KB Output is correct
2 Correct 1568 ms 1528 KB Output is correct
3 Correct 1820 ms 1520 KB Output is correct
4 Correct 1779 ms 1460 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 165 ms 1160 KB Output is correct
7 Correct 52 ms 1116 KB Output is correct
8 Correct 13 ms 1112 KB Output is correct
9 Correct 46 ms 1228 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 92 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 691 ms 1216 KB Output is correct
2 Correct 671 ms 1220 KB Output is correct
3 Correct 702 ms 1224 KB Output is correct
4 Correct 670 ms 1220 KB Output is correct
5 Correct 691 ms 1216 KB Output is correct
6 Correct 758 ms 1220 KB Output is correct
7 Correct 227 ms 1212 KB Output is correct
8 Correct 744 ms 1120 KB Output is correct
9 Correct 753 ms 1196 KB Output is correct
10 Correct 799 ms 1180 KB Output is correct
11 Correct 837 ms 1196 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 0 ms 660 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 0 ms 604 KB Output is correct
29 Correct 0 ms 604 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 272 ms 1576 KB Output is correct
33 Correct 344 ms 1572 KB Output is correct
34 Correct 390 ms 1568 KB Output is correct
35 Correct 1266 ms 1548 KB Output is correct
36 Correct 1155 ms 1548 KB Output is correct
37 Correct 351 ms 1524 KB Output is correct
38 Correct 1567 ms 1528 KB Output is correct
39 Correct 970 ms 1516 KB Output is correct
40 Correct 275 ms 1492 KB Output is correct
41 Correct 1169 ms 1492 KB Output is correct
42 Correct 1087 ms 1472 KB Output is correct
43 Correct 318 ms 1432 KB Output is correct
44 Correct 1332 ms 1532 KB Output is correct
45 Correct 1330 ms 1532 KB Output is correct
46 Correct 1338 ms 1532 KB Output is correct
47 Correct 1341 ms 1536 KB Output is correct
48 Correct 1320 ms 1536 KB Output is correct
49 Correct 364 ms 1112 KB Output is correct
50 Correct 1220 ms 1376 KB Output is correct
51 Correct 1214 ms 1424 KB Output is correct
52 Correct 211 ms 1504 KB Output is correct
53 Correct 145 ms 1372 KB Output is correct
54 Correct 1090 ms 1520 KB Output is correct
55 Correct 1338 ms 1504 KB Output is correct
56 Correct 1311 ms 1500 KB Output is correct
57 Correct 180 ms 1480 KB Output is correct
58 Correct 1322 ms 1460 KB Output is correct
59 Correct 1415 ms 1540 KB Output is correct
60 Correct 1338 ms 1544 KB Output is correct
61 Correct 1477 ms 1536 KB Output is correct
62 Correct 1173 ms 1536 KB Output is correct
63 Correct 1269 ms 1448 KB Output is correct
64 Correct 1372 ms 1548 KB Output is correct
65 Correct 1568 ms 1528 KB Output is correct
66 Correct 1820 ms 1520 KB Output is correct
67 Correct 1779 ms 1460 KB Output is correct
68 Correct 1 ms 604 KB Output is correct
69 Correct 165 ms 1160 KB Output is correct
70 Correct 52 ms 1116 KB Output is correct
71 Correct 13 ms 1112 KB Output is correct
72 Correct 46 ms 1228 KB Output is correct
73 Correct 3 ms 604 KB Output is correct
74 Correct 92 ms 1116 KB Output is correct
75 Correct 197 ms 1568 KB Output is correct
76 Correct 315 ms 1616 KB Output is correct
77 Correct 401 ms 1372 KB Output is correct
78 Correct 382 ms 1616 KB Output is correct
79 Correct 402 ms 1572 KB Output is correct
80 Correct 1782 ms 1536 KB Output is correct
81 Correct 932 ms 1532 KB Output is correct
82 Correct 1444 ms 1536 KB Output is correct
83 Correct 1208 ms 1524 KB Output is correct
84 Correct 1165 ms 1616 KB Output is correct
85 Correct 179 ms 1532 KB Output is correct
86 Correct 987 ms 1532 KB Output is correct
87 Correct 161 ms 1368 KB Output is correct
88 Correct 627 ms 1524 KB Output is correct
89 Correct 1077 ms 1516 KB Output is correct
90 Correct 275 ms 1372 KB Output is correct
91 Correct 466 ms 1372 KB Output is correct
92 Correct 1069 ms 1532 KB Output is correct
93 Correct 796 ms 1536 KB Output is correct
94 Correct 661 ms 1528 KB Output is correct
95 Correct 1082 ms 1524 KB Output is correct
96 Correct 1397 ms 1456 KB Output is correct
97 Correct 683 ms 1536 KB Output is correct
98 Correct 867 ms 1520 KB Output is correct
99 Correct 765 ms 1500 KB Output is correct
100 Correct 386 ms 1284 KB Output is correct