Submission #983640

# Submission time Handle Problem Language Result Execution time Memory
983640 2024-05-15T19:45:15 Z CSQ31 Toy Train (IOI17_train) C++17
23 / 100
230 ms 1724 KB
#include "train.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(a) (int)(a.size())
const int MAXN = 5555;
vector<int>g[MAXN],gr[MAXN];
std::vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
	int n = sz(a);
	vector<int>win(n,0);
	for(int i=0;i<sz(u);i++){
		g[u[i]].push_back(v[i]);
		gr[v[i]].push_back(u[i]);
	}
	for(int i=0;i<n;i++){
		if(!r[i])continue;
		vector<bool>path(n,0);
		vector<int>cnt(n,0);
		for(int j=0;j<n;j++){
			if(!a[j])cnt[j] = sz(g[j]);
		}

		queue<int>q;
		q.push(i);
		path[i] = 1;
		while(!q.empty()){
			int v = q.front();
			q.pop();
			for(int x:gr[v]){
				if(path[x])continue;
				if(a[x]){
					path[x] = 1;
					q.push(x);
				}else{
					cnt[x]--;
					if(!cnt[x]){
						path[x] = 1;
						q.push(x);
					}
				}
			}
		}
		//path(x) = x can be forced to go to i
		bool cyc = 0;
		int c = 0;
		for(int x:g[i]){
			if(path[x] && a[i])cyc = 1;
			if(path[x] && !a[i])c++;
		}
		if(c == sz(g[i]))cyc = 1;
		if(cyc){
			for(int j=0;j<n;j++){
				if(path[j])win[j] = 1;
			}
		}
	}
	vector<int>cnt(n,0);
	queue<int>q;
	for(int i=0;i<n;i++){
		cnt[i] = sz(g[i]);
		if(win[i])q.push(i);
	}
	while(!q.empty()){
		int v = q.front();
		q.pop();
		for(int x:gr[v]){
			if(win[x])continue;
			if(a[x]){
				win[x] = 1;
				q.push(x);
			}else{
				cnt[x]--;
				if(!cnt[x]){
					win[x] = 1;
					q.push(x);
				}

			}
		}
	}
	return win;
	
}
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 1116 KB 3rd lines differ - on the 26th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 604 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 1604 KB Output is correct
2 Correct 58 ms 1632 KB Output is correct
3 Correct 62 ms 1628 KB Output is correct
4 Correct 184 ms 1624 KB Output is correct
5 Correct 53 ms 1624 KB Output is correct
6 Correct 16 ms 1624 KB Output is correct
7 Correct 230 ms 1724 KB Output is correct
8 Correct 6 ms 1608 KB Output is correct
9 Correct 5 ms 1628 KB Output is correct
10 Correct 6 ms 1628 KB Output is correct
11 Correct 8 ms 1628 KB Output is correct
12 Correct 5 ms 1628 KB Output is correct
13 Correct 6 ms 1708 KB Output is correct
14 Correct 6 ms 1624 KB Output is correct
15 Correct 6 ms 1624 KB Output is correct
16 Correct 6 ms 1628 KB Output is correct
17 Correct 6 ms 1628 KB Output is correct
18 Correct 84 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 1372 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 Correct 6 ms 1372 KB Output is correct
2 Correct 6 ms 1616 KB Output is correct
3 Correct 6 ms 1628 KB Output is correct
4 Correct 6 ms 1628 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 3 ms 1224 KB Output is correct
7 Correct 4 ms 1372 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 4 ms 1368 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 4 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 1116 KB 3rd lines differ - on the 26th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -