Submission #978876

# Submission time Handle Problem Language Result Execution time Memory
978876 2024-05-09T22:34:48 Z Lalic Toy Train (IOI17_train) C++17
100 / 100
516 ms 1644 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int N;
vector<int> adj[5005];

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
	N=(int)a.size();
	
	vector<int> ans(N, 1);
	for(int i=0;i<(int)u.size();i++){
		adj[v[i]].pb(u[i]);
	}
	
	auto recalc = [&]() -> void{
		vector<int> rem(N, 0), gin(N, 0);
		
		for(auto val : u) gin[val]++;
		
		queue<int> q;
		for(int i=0;i<N;i++){
			if(r[i] && ans[i]){
				q.push(i);
				rem[i]=1;
			}
		}
		
		while(!q.empty()){
			int curr=q.front();
			q.pop();
			
			for(auto at : adj[curr]){
				if(rem[at]) continue;
				
				gin[at]--;
				if(a[at] || !gin[at]){
					rem[at]=1;
					q.push(at);
				}
			}
		}
		
		for(int i=0;i<N;i++){
			if(!rem[i]){
				ans[i]=0;
				q.push(i);
			}
		}
		
		gin.assign(N, 0);
		for(auto val :  u) gin[val]++;
		
		while(!q.empty()){
			int curr=q.front();
			q.pop();
			
			for(auto at : adj[curr]){
				if(!ans[at]) continue;
				
				gin[at]--;
				if(!a[at] || !gin[at]){
					ans[at]=0;
					q.push(at);
				}
			}
		}
	};
	
	vector<int> bef(N, 0);
	while(bef!=ans){
		bef=ans;
		recalc();
	}
	
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 860 KB Output is correct
2 Correct 4 ms 1112 KB Output is correct
3 Correct 3 ms 984 KB Output is correct
4 Correct 3 ms 856 KB Output is correct
5 Correct 3 ms 856 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 856 KB Output is correct
9 Correct 3 ms 856 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 544 KB Output is correct
20 Correct 0 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 1372 KB Output is correct
2 Correct 120 ms 1620 KB Output is correct
3 Correct 174 ms 1452 KB Output is correct
4 Correct 5 ms 1368 KB Output is correct
5 Correct 6 ms 1372 KB Output is correct
6 Correct 6 ms 1368 KB Output is correct
7 Correct 5 ms 1368 KB Output is correct
8 Correct 5 ms 1372 KB Output is correct
9 Correct 5 ms 1368 KB Output is correct
10 Correct 5 ms 1372 KB Output is correct
11 Correct 5 ms 1372 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 5 ms 1372 KB Output is correct
14 Correct 5 ms 1308 KB Output is correct
15 Correct 5 ms 1368 KB Output is correct
16 Correct 5 ms 1368 KB Output is correct
17 Correct 5 ms 1372 KB Output is correct
18 Correct 221 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1112 KB Output is correct
2 Correct 5 ms 1116 KB Output is correct
3 Correct 5 ms 1372 KB Output is correct
4 Correct 5 ms 1340 KB Output is correct
5 Correct 5 ms 1624 KB Output is correct
6 Correct 5 ms 1196 KB Output is correct
7 Correct 5 ms 1372 KB Output is correct
8 Correct 5 ms 1372 KB Output is correct
9 Correct 5 ms 1372 KB Output is correct
10 Correct 5 ms 1372 KB Output is correct
11 Correct 5 ms 1468 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 5 ms 1620 KB Output is correct
14 Correct 5 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1372 KB Output is correct
2 Correct 5 ms 1212 KB Output is correct
3 Correct 6 ms 1372 KB Output is correct
4 Correct 5 ms 1288 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 3 ms 1116 KB Output is correct
8 Correct 4 ms 1116 KB Output is correct
9 Correct 4 ms 1116 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 3 ms 1084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 860 KB Output is correct
2 Correct 4 ms 1112 KB Output is correct
3 Correct 3 ms 984 KB Output is correct
4 Correct 3 ms 856 KB Output is correct
5 Correct 3 ms 856 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 856 KB Output is correct
9 Correct 3 ms 856 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 544 KB Output is correct
31 Correct 0 ms 564 KB Output is correct
32 Correct 62 ms 1372 KB Output is correct
33 Correct 120 ms 1620 KB Output is correct
34 Correct 174 ms 1452 KB Output is correct
35 Correct 5 ms 1368 KB Output is correct
36 Correct 6 ms 1372 KB Output is correct
37 Correct 6 ms 1368 KB Output is correct
38 Correct 5 ms 1368 KB Output is correct
39 Correct 5 ms 1372 KB Output is correct
40 Correct 5 ms 1368 KB Output is correct
41 Correct 5 ms 1372 KB Output is correct
42 Correct 5 ms 1372 KB Output is correct
43 Correct 4 ms 1372 KB Output is correct
44 Correct 5 ms 1372 KB Output is correct
45 Correct 5 ms 1308 KB Output is correct
46 Correct 5 ms 1368 KB Output is correct
47 Correct 5 ms 1368 KB Output is correct
48 Correct 5 ms 1372 KB Output is correct
49 Correct 221 ms 1144 KB Output is correct
50 Correct 4 ms 1112 KB Output is correct
51 Correct 5 ms 1116 KB Output is correct
52 Correct 5 ms 1372 KB Output is correct
53 Correct 5 ms 1340 KB Output is correct
54 Correct 5 ms 1624 KB Output is correct
55 Correct 5 ms 1196 KB Output is correct
56 Correct 5 ms 1372 KB Output is correct
57 Correct 5 ms 1372 KB Output is correct
58 Correct 5 ms 1372 KB Output is correct
59 Correct 5 ms 1372 KB Output is correct
60 Correct 5 ms 1468 KB Output is correct
61 Correct 5 ms 1372 KB Output is correct
62 Correct 5 ms 1620 KB Output is correct
63 Correct 5 ms 1372 KB Output is correct
64 Correct 5 ms 1372 KB Output is correct
65 Correct 5 ms 1212 KB Output is correct
66 Correct 6 ms 1372 KB Output is correct
67 Correct 5 ms 1288 KB Output is correct
68 Correct 1 ms 604 KB Output is correct
69 Correct 3 ms 860 KB Output is correct
70 Correct 3 ms 1116 KB Output is correct
71 Correct 4 ms 1116 KB Output is correct
72 Correct 4 ms 1116 KB Output is correct
73 Correct 2 ms 604 KB Output is correct
74 Correct 3 ms 1084 KB Output is correct
75 Correct 125 ms 1412 KB Output is correct
76 Correct 130 ms 1444 KB Output is correct
77 Correct 185 ms 1372 KB Output is correct
78 Correct 189 ms 1448 KB Output is correct
79 Correct 186 ms 1448 KB Output is correct
80 Correct 6 ms 1368 KB Output is correct
81 Correct 5 ms 1368 KB Output is correct
82 Correct 6 ms 1372 KB Output is correct
83 Correct 6 ms 1212 KB Output is correct
84 Correct 6 ms 1216 KB Output is correct
85 Correct 6 ms 1368 KB Output is correct
86 Correct 6 ms 1368 KB Output is correct
87 Correct 6 ms 1372 KB Output is correct
88 Correct 8 ms 1372 KB Output is correct
89 Correct 6 ms 1372 KB Output is correct
90 Correct 12 ms 1372 KB Output is correct
91 Correct 10 ms 1372 KB Output is correct
92 Correct 21 ms 1372 KB Output is correct
93 Correct 16 ms 1372 KB Output is correct
94 Correct 18 ms 1364 KB Output is correct
95 Correct 19 ms 1444 KB Output is correct
96 Correct 52 ms 1116 KB Output is correct
97 Correct 309 ms 1372 KB Output is correct
98 Correct 467 ms 1396 KB Output is correct
99 Correct 516 ms 1644 KB Output is correct
100 Correct 217 ms 1112 KB Output is correct