Submission #641999

# Submission time Handle Problem Language Result Execution time Memory
641999 2022-09-18T08:39:17 Z QwertyPi Toy Train (IOI17_train) C++14
0 / 100
2000 ms 78604 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 a[N];
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> win(n, 0), charged(n, 0), ans(n, 0), cnt(n, 0);
	for(int i = 0; i < m; i++){
		G[u[i]].push_back(v[i]);
		H[v[i]].push_back(u[i]);
	}
	fill(win.begin(), win.end(), 0);
	fill(cnt.begin(), cnt.end(), 0);
	priority_queue<pair<int, int>> pq;
	for(int j = 0; j < n; j++){
		if(r[j] == 1){
			charged[j] = true;
			for(auto k : G[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.fi & ((1 << 16) - 1), c = t.se;
		if(win[v]) continue;
		if(t.fi >= G[v].size()) {
			charged[v] = true;
			for(auto k : G[v]){
				cnt[k]++; pq.push({(a[k] << 16) + cnt[k], k});
			}
		}
	}

	for(int u = 0; u < n; u++){
		bool exist = false, all = true;
		for(auto v : G[u]){
			if(charged[v]) exist = true;
			if(!charged[v]) all = false;
		}
		ans[u] = a[u] ? exist : all;
	}
	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:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   if(t.fi >= G[v].size()) {
      |      ~~~~~^~~~~~~~~~~~~~
train.cpp:37:35: warning: unused variable 'c' [-Wunused-variable]
   37 |   int v = t.fi & ((1 << 16) - 1), c = t.se;
      |                                   ^
# Verdict Execution time Memory Grader output
1 Execution timed out 2086 ms 34204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 66380 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 98 ms 14388 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 631 ms 78604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1620 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2086 ms 34204 KB Time limit exceeded
2 Halted 0 ms 0 KB -