Submission #642035

# Submission time Handle Problem Language Result Execution time Memory
642035 2022-09-18T10:19:20 Z QwertyPi Toy Train (IOI17_train) C++14
100 / 100
805 ms 1908 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#ifndef hkoi
	#include "train.h"
#endif
 
using namespace std;
 
const int N = 5001, M = 20001;
int n, m;
vector<pair<int, int>> G[N], H[N];
 
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	::n = a.size(), ::m = u.size();
	std::vector<int> losed(n, 0), ans(n, 0);
	std::vector<bool> self(n, 0);
	for(int i = 0; i < n; i++){
		G[i].clear(); H[i].clear();
	}
	for(int i = 0; i < m; i++){
		G[u[i]].push_back({v[i], i});
		H[v[i]].push_back({u[i], i});
		if(u[i] == v[i])
			self[u[i]] = true;
	}
	for(int tr = 0; tr < n; tr++){
		bool changing = false;
		std::vector<int> charged(n, 0), cnt(n, 0);
		deque<pair<int, int>> dq;
		vector<bool> used(m, 0);
		for(int i = 0; i < n; i++) if(r[i] && !losed[i]) charged[i] = true;
		vector<bool> rch(n, 0); for(int i = 0; i < n; i++) if(charged[i]) rch[i] = true;
		for(int j = 0; j < n; j++){
			if(charged[j] == true){
				for(auto& [k, id] : H[j]){
					used[id] = true;
					cnt[k]++; dq.push_back({(a[k] << 16) + cnt[k], k});
				}
			}
		}
		while(dq.size()){
			pair<int, int> t = dq.front(); dq.pop_front();
			int v = t.se;
			if(t.fi >= G[v].size()) {
				if(charged[v]) continue;
				charged[v] = true;
				for(auto& [k, id] : H[v]){
					if(charged[k] || used[id]) continue;
					used[id] = true;
					cnt[k]++; dq.push_back({(a[k] << 16) + cnt[k], k});
				}
			}
		}
	
		used.clear();
		fill(cnt.begin(), cnt.end(), 0);
		
		for(int j = 0; j < n; j++){
			if(!charged[j]){
				if(!losed[j]) changing = true;
				losed[j] = true;
				for(auto& [k, id] : H[j]){
					if(losed[k]) continue;
					used[id] = true;
					cnt[k]++; dq.push_back({((!a[k]) << 16) + cnt[k], k});
				}
			}
		}
		while(dq.size()){
			pair<int, int> t = dq.front(); dq.pop_front();
			int v = t.se;
			if(t.fi >= G[v].size() - (!rch[v] && self[v])) {
				if(losed[v]) continue;
				changing = true; losed[v] = true;
				for(auto& [k, id] : H[v]){
					if(losed[k] || used[id]) continue;
					used[id] = true;
					cnt[k]++; dq.push_back({((!a[k]) << 16) + cnt[k], k});
				}
			}
		}
		if(!changing) break;
	}
	for(int u = 0; u < n; u++){
		ans[u] = !losed[u];
	}
	return ans;
}
 
#ifdef hkoi
 
int main(){
	int n, m; cin >> n >> m;
	vector<int> a; for(int i = 0; i < n; i++) {
		int v; cin >> v; a.push_back(v);
	}
	vector<int> r; for(int i = 0; i < n; i++) {
		int v; cin >> v; r.push_back(v);
	}
	vector<int> u, v; for(int i = 0; i < m; i++){
		int x, y; cin >> x >> y; 
		u.push_back(x); v.push_back(y);
	}
	vector<int> w = who_wins(a, r, u, v);
	for(int i = 0; i < n; i++){
		cout << w[i] << ' ';
	}
	cout << '\n';
}
 
#endif

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:39:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   39 |     for(auto& [k, id] : H[j]){
      |               ^
train.cpp:48:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    if(t.fi >= G[v].size()) {
      |       ~~~~~^~~~~~~~~~~~~~
train.cpp:51:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |     for(auto& [k, id] : H[v]){
      |               ^
train.cpp:66:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   66 |     for(auto& [k, id] : H[j]){
      |               ^
train.cpp:76:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |    if(t.fi >= G[v].size() - (!rch[v] && self[v])) {
      |       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
train.cpp:79:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   79 |     for(auto& [k, id] : H[v]){
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1108 KB Output is correct
2 Correct 7 ms 1108 KB Output is correct
3 Correct 7 ms 1108 KB Output is correct
4 Correct 7 ms 1108 KB Output is correct
5 Correct 6 ms 1108 KB Output is correct
6 Correct 7 ms 1140 KB Output is correct
7 Correct 7 ms 1136 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 5 ms 1108 KB Output is correct
10 Correct 4 ms 980 KB Output is correct
11 Correct 4 ms 1108 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 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 1660 KB Output is correct
2 Correct 185 ms 1832 KB Output is correct
3 Correct 257 ms 1836 KB Output is correct
4 Correct 8 ms 1876 KB Output is correct
5 Correct 15 ms 1828 KB Output is correct
6 Correct 13 ms 1832 KB Output is correct
7 Correct 8 ms 1872 KB Output is correct
8 Correct 7 ms 1860 KB Output is correct
9 Correct 7 ms 1748 KB Output is correct
10 Correct 8 ms 1748 KB Output is correct
11 Correct 10 ms 1748 KB Output is correct
12 Correct 7 ms 1700 KB Output is correct
13 Correct 8 ms 1876 KB Output is correct
14 Correct 8 ms 1836 KB Output is correct
15 Correct 8 ms 1876 KB Output is correct
16 Correct 7 ms 1836 KB Output is correct
17 Correct 8 ms 1832 KB Output is correct
18 Correct 341 ms 1324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1492 KB Output is correct
2 Correct 7 ms 1492 KB Output is correct
3 Correct 8 ms 1620 KB Output is correct
4 Correct 9 ms 1700 KB Output is correct
5 Correct 11 ms 1628 KB Output is correct
6 Correct 8 ms 1492 KB Output is correct
7 Correct 8 ms 1492 KB Output is correct
8 Correct 8 ms 1492 KB Output is correct
9 Correct 9 ms 1620 KB Output is correct
10 Correct 8 ms 1748 KB Output is correct
11 Correct 10 ms 1748 KB Output is correct
12 Correct 8 ms 1672 KB Output is correct
13 Correct 8 ms 1620 KB Output is correct
14 Correct 7 ms 1480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1664 KB Output is correct
2 Correct 7 ms 1600 KB Output is correct
3 Correct 9 ms 1664 KB Output is correct
4 Correct 8 ms 1484 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 4 ms 1108 KB Output is correct
7 Correct 5 ms 1364 KB Output is correct
8 Correct 5 ms 1492 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 5 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1108 KB Output is correct
2 Correct 7 ms 1108 KB Output is correct
3 Correct 7 ms 1108 KB Output is correct
4 Correct 7 ms 1108 KB Output is correct
5 Correct 6 ms 1108 KB Output is correct
6 Correct 7 ms 1140 KB Output is correct
7 Correct 7 ms 1136 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 5 ms 1108 KB Output is correct
10 Correct 4 ms 980 KB Output is correct
11 Correct 4 ms 1108 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 0 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 0 ms 468 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 0 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 0 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 0 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 0 ms 468 KB Output is correct
32 Correct 106 ms 1660 KB Output is correct
33 Correct 185 ms 1832 KB Output is correct
34 Correct 257 ms 1836 KB Output is correct
35 Correct 8 ms 1876 KB Output is correct
36 Correct 15 ms 1828 KB Output is correct
37 Correct 13 ms 1832 KB Output is correct
38 Correct 8 ms 1872 KB Output is correct
39 Correct 7 ms 1860 KB Output is correct
40 Correct 7 ms 1748 KB Output is correct
41 Correct 8 ms 1748 KB Output is correct
42 Correct 10 ms 1748 KB Output is correct
43 Correct 7 ms 1700 KB Output is correct
44 Correct 8 ms 1876 KB Output is correct
45 Correct 8 ms 1836 KB Output is correct
46 Correct 8 ms 1876 KB Output is correct
47 Correct 7 ms 1836 KB Output is correct
48 Correct 8 ms 1832 KB Output is correct
49 Correct 341 ms 1324 KB Output is correct
50 Correct 7 ms 1492 KB Output is correct
51 Correct 7 ms 1492 KB Output is correct
52 Correct 8 ms 1620 KB Output is correct
53 Correct 9 ms 1700 KB Output is correct
54 Correct 11 ms 1628 KB Output is correct
55 Correct 8 ms 1492 KB Output is correct
56 Correct 8 ms 1492 KB Output is correct
57 Correct 8 ms 1492 KB Output is correct
58 Correct 9 ms 1620 KB Output is correct
59 Correct 8 ms 1748 KB Output is correct
60 Correct 10 ms 1748 KB Output is correct
61 Correct 8 ms 1672 KB Output is correct
62 Correct 8 ms 1620 KB Output is correct
63 Correct 7 ms 1480 KB Output is correct
64 Correct 8 ms 1664 KB Output is correct
65 Correct 7 ms 1600 KB Output is correct
66 Correct 9 ms 1664 KB Output is correct
67 Correct 8 ms 1484 KB Output is correct
68 Correct 1 ms 596 KB Output is correct
69 Correct 4 ms 1108 KB Output is correct
70 Correct 5 ms 1364 KB Output is correct
71 Correct 5 ms 1492 KB Output is correct
72 Correct 6 ms 1492 KB Output is correct
73 Correct 2 ms 852 KB Output is correct
74 Correct 5 ms 1364 KB Output is correct
75 Correct 282 ms 1788 KB Output is correct
76 Correct 345 ms 1832 KB Output is correct
77 Correct 465 ms 1816 KB Output is correct
78 Correct 460 ms 1748 KB Output is correct
79 Correct 460 ms 1820 KB Output is correct
80 Correct 9 ms 1876 KB Output is correct
81 Correct 11 ms 1868 KB Output is correct
82 Correct 10 ms 1828 KB Output is correct
83 Correct 13 ms 1832 KB Output is correct
84 Correct 13 ms 1828 KB Output is correct
85 Correct 14 ms 1908 KB Output is correct
86 Correct 15 ms 1876 KB Output is correct
87 Correct 9 ms 1876 KB Output is correct
88 Correct 19 ms 1876 KB Output is correct
89 Correct 9 ms 1868 KB Output is correct
90 Correct 27 ms 1888 KB Output is correct
91 Correct 32 ms 1876 KB Output is correct
92 Correct 54 ms 1876 KB Output is correct
93 Correct 47 ms 1848 KB Output is correct
94 Correct 46 ms 1872 KB Output is correct
95 Correct 50 ms 1872 KB Output is correct
96 Correct 104 ms 1728 KB Output is correct
97 Correct 496 ms 1896 KB Output is correct
98 Correct 696 ms 1876 KB Output is correct
99 Correct 805 ms 1876 KB Output is correct
100 Correct 348 ms 1424 KB Output is correct