Submission #642012

# Submission time Handle Problem Language Result Execution time Memory
642012 2022-09-18T09:26:21 Z QwertyPi Toy Train (IOI17_train) C++14
16 / 100
102 ms 2896 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<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), charged(n, 0), ans(n, 0), cnt(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]);
		H[v[i]].push_back(u[i]);
		if(u[i] == v[i])
			self[u[i]] = true;
	}
	priority_queue<pair<int, int>> pq;
	set<pair<int, int>> used;
	set<int> rch; for(int i = 0; i < n; i++) if(r[i]) rch.insert(i);
	for(int j = 0; j < n; j++){
		if(r[j] == 1){
			charged[j] = true;
			for(auto k : H[j]){
				used.insert({k, j});
				cnt[k]++; pq.push({(a[k] << 16) + cnt[k], k});
			}
		}
	}
	while(pq.size()){
		pair<int, int> t = pq.top(); pq.pop();
		int v = t.se;
		if(t.fi >= G[v].size()) {
			charged[v] = true;
			for(auto k : H[v]){
				if(used.count({k, v})) continue;
				used.insert({k, v});
				cnt[k]++; pq.push({(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 : H[j]){
				used.insert({k, j});
				cnt[k]++; pq.push({((!a[k]) << 16) + cnt[k], k});
			}
		}
	}
	while(pq.size()){
		pair<int, int> t = pq.top(); pq.pop();
		int v = t.se;
		if(t.fi >= G[v].size() - (rch.find(v) == rch.end() && self[v])) {
			losed[v] = true;
			for(auto k : H[v]){
				if(used.count({k, v})) continue;
				used.insert({k, v});
				cnt[k]++; pq.push({((!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:43:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   if(t.fi >= G[v].size()) {
      |      ~~~~~^~~~~~~~~~~~~~
train.cpp:68:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   if(t.fi >= G[v].size() - (rch.find(v) == rch.end() && self[v])) {
      |      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1572 KB Output is correct
2 Correct 9 ms 1492 KB Output is correct
3 Correct 8 ms 1576 KB Output is correct
4 Correct 8 ms 1572 KB Output is correct
5 Correct 8 ms 1492 KB Output is correct
6 Correct 8 ms 1572 KB Output is correct
7 Correct 9 ms 1576 KB Output is correct
8 Correct 6 ms 1572 KB Output is correct
9 Correct 8 ms 1472 KB Output is correct
10 Correct 7 ms 1364 KB Output is correct
11 Correct 6 ms 1316 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 Incorrect 1 ms 468 KB 3rd lines differ - on the 3rd token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 102 ms 2604 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2360 KB Output is correct
2 Correct 18 ms 2164 KB Output is correct
3 Correct 36 ms 2524 KB Output is correct
4 Correct 47 ms 2748 KB Output is correct
5 Correct 19 ms 2292 KB Output is correct
6 Correct 19 ms 2348 KB Output is correct
7 Correct 22 ms 2352 KB Output is correct
8 Correct 37 ms 2472 KB Output is correct
9 Correct 19 ms 2764 KB Output is correct
10 Correct 22 ms 2776 KB Output is correct
11 Correct 19 ms 2896 KB Output is correct
12 Correct 19 ms 2764 KB Output is correct
13 Correct 19 ms 2352 KB Output is correct
14 Correct 18 ms 2244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2260 KB Output is correct
2 Correct 28 ms 2496 KB Output is correct
3 Correct 24 ms 2364 KB Output is correct
4 Correct 19 ms 2388 KB Output is correct
5 Correct 4 ms 596 KB Output is correct
6 Correct 10 ms 1492 KB Output is correct
7 Correct 53 ms 1820 KB Output is correct
8 Incorrect 60 ms 1780 KB 3rd lines differ - on the 5th token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1572 KB Output is correct
2 Correct 9 ms 1492 KB Output is correct
3 Correct 8 ms 1576 KB Output is correct
4 Correct 8 ms 1572 KB Output is correct
5 Correct 8 ms 1492 KB Output is correct
6 Correct 8 ms 1572 KB Output is correct
7 Correct 9 ms 1576 KB Output is correct
8 Correct 6 ms 1572 KB Output is correct
9 Correct 8 ms 1472 KB Output is correct
10 Correct 7 ms 1364 KB Output is correct
11 Correct 6 ms 1316 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 Incorrect 1 ms 468 KB 3rd lines differ - on the 3rd token, expected: '0', found: '1'
17 Halted 0 ms 0 KB -