Submission #642022

# Submission time Handle Problem Language Result Execution time Memory
642022 2022-09-18T09:56:33 Z QwertyPi Toy Train (IOI17_train) C++14
15 / 100
2000 ms 1752 KB
#include <bits/stdc++.h>
#define fi first
#define se second

#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++){
		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()) {
				charged[v] = true;
				for(auto& [k, id] : H[v]){
					if(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]){
				losed[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() - (!rch[v] && self[v])) {
				losed[v] = true;
				for(auto& [k, id] : H[v]){
					if(used[id]) continue;
					used[id] = true;
					cnt[k]++; dq.push_back({((!a[k]) << 16) + cnt[k], k});
				}
			}
		}
	}
	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:36:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   36 |     for(auto& [k, id] : H[j]){
      |               ^
train.cpp:45: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]
   45 |    if(t.fi >= G[v].size()) {
      |       ~~~~~^~~~~~~~~~~~~~
train.cpp:47:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   47 |     for(auto& [k, id] : H[v]){
      |               ^
train.cpp:61:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |     for(auto& [k, id] : H[j]){
      |               ^
train.cpp:70: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]
   70 |    if(t.fi >= G[v].size() - (!rch[v] && self[v])) {
      |       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
train.cpp:72:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   72 |     for(auto& [k, id] : H[v]){
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 1360 ms 1132 KB Output is correct
2 Correct 1363 ms 1128 KB Output is correct
3 Correct 1367 ms 1124 KB Output is correct
4 Correct 1410 ms 1140 KB Output is correct
5 Correct 1452 ms 1124 KB Output is correct
6 Correct 1385 ms 1116 KB Output is correct
7 Correct 1197 ms 1136 KB Output is correct
8 Correct 1402 ms 1120 KB Output is correct
9 Correct 1333 ms 1108 KB Output is correct
10 Correct 1290 ms 1084 KB Output is correct
11 Correct 1068 ms 1084 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 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 540 KB Output is correct
8 Correct 1 ms 540 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 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 540 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 540 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 540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2069 ms 1752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2041 ms 1492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2083 ms 1620 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1360 ms 1132 KB Output is correct
2 Correct 1363 ms 1128 KB Output is correct
3 Correct 1367 ms 1124 KB Output is correct
4 Correct 1410 ms 1140 KB Output is correct
5 Correct 1452 ms 1124 KB Output is correct
6 Correct 1385 ms 1116 KB Output is correct
7 Correct 1197 ms 1136 KB Output is correct
8 Correct 1402 ms 1120 KB Output is correct
9 Correct 1333 ms 1108 KB Output is correct
10 Correct 1290 ms 1084 KB Output is correct
11 Correct 1068 ms 1084 KB Output is correct
12 Correct 1 ms 468 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 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 540 KB Output is correct
19 Correct 1 ms 540 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 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 540 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 540 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 540 KB Output is correct
32 Execution timed out 2069 ms 1752 KB Time limit exceeded
33 Halted 0 ms 0 KB -