Submission #761361

# Submission time Handle Problem Language Result Execution time Memory
761361 2023-06-19T14:34:07 Z minhcool Toy Train (IOI17_train) C++17
26 / 100
185 ms 15344 KB
#ifndef local
#include "train.h"
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 3e5 + 5;
 
const int oo = 1e18 + 7, mod = 1e9 + 7;
 
int n, a[N];
 
mt19937 rng(1);
 
int rnd(int l, int r){
	int temp = rng() % (r - l + 1);
	return abs(temp) + l;
}
 
vector<int> Adj[N], Adj2[N];
 
bool out[N];
 
int deg[N], deg2[N];
 
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> U, vector<int> V){
	n = a.size();
	for(int i = 0; i < U.size(); i++){
		Adj[V[i]].pb(U[i]);
		Adj2[U[i]].pb(V[i]);
		//Adj[U[i]].pb(V[i]);
	}
	for(int i = 0; i < n; i++) deg2[i] = Adj2[i].size();
	while(1){
		vector<bool> vis(n + 1);
		for(int i = 0; i < n; i++){
			if(out[i]) continue;
			vis[i] = r[i];
			deg[i] = 0;
		}
		queue<int> q;
		for(int i = 0; i < n; i++){
			if(out[i]) continue;
			if(r[i]) q.push(i);
		}
		while(!q.empty()){
			int u = q.front();
		//	cout << u << "\n";
			vis[u] = 1;
			q.pop();
			for(auto v : Adj[u]){
				if(vis[v]) continue;
				if(out[v]) continue;
				deg[v]++;
				if(a[v] == 1 && deg[v] == 1) q.push(v);
				if(a[v] == 0 && deg[v] == deg2[v]) q.push(v);		
			}
			//vis[u] = 1;
			//for(auto v : Adj[u]){
			//	if(vis[v] || out[v]) continue;
			//	q.push(v);
			//}
		}
		//cout << "\n";
		for(int i = 0; i < n; i++){
			if(!out[i] && !vis[i]) q.push(i);
			vis[i] = deg[i] = 0;
		}
		while(!q.empty()){
			int u = q.front();
			//cout << "OK " << u << "\n";
			vis[u] = 1;
			q.pop();
			for(auto v : Adj[u]){
				if(vis[v]) continue;
				if(out[v]) continue;
				deg[v]++;
				if(a[v] == 0 && deg[v] == 1) q.push(v);
				if(a[v] == 1 && deg[v] == deg2[v]) q.push(v);		
			}	
		}
		//exit(0);
		int cnt = 0;
		for(int i = 0; i < n; i++){
			if(out[i] || !vis[i]) continue;
		//	cout << i << "\n";
			out[i] = 1;
			for(auto it : Adj[i]) deg2[it]--;
			cnt++;
		}
		if(!cnt) break;
	}	
	vector<int> ans;
	for(int i = 0; i < n; i++) ans.pb(!out[i]);
	return ans;
}
 
//#define local
#ifdef local
void process(){
	int n, m;
	cin >> n >> m;
	vector<int> v1, v2;
	v1.resize(n), v2.resize(n);
	vector<int> v3, v4;
	for(int i = 0; i < n; i++) cin >> v1[i];
	for(int i = 0; i < n; i++) cin >> v2[i];
	for(int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		v3.pb(x), v4.pb(y);
	}
	vector<int> v = who_wins(v1, v2, v3, v4);
	for(int i = 0; i < n; i++) cout << v[i] << " ";
	cout << "\n";
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	process();
}
#endif

Compilation message

train.cpp:21:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   21 | const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                ~~~~~^~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for(int i = 0; i < U.size(); i++){
      |                 ~~^~~~~~~~~~
train.cpp:79:20: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   79 |    vis[i] = deg[i] = 0;
      |             ~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14932 KB Output is correct
2 Correct 11 ms 14932 KB Output is correct
3 Correct 11 ms 14908 KB Output is correct
4 Correct 10 ms 15004 KB Output is correct
5 Correct 10 ms 15024 KB Output is correct
6 Correct 10 ms 14984 KB Output is correct
7 Correct 11 ms 14992 KB Output is correct
8 Correct 10 ms 14932 KB Output is correct
9 Correct 11 ms 14920 KB Output is correct
10 Correct 12 ms 14932 KB Output is correct
11 Correct 10 ms 14932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14304 KB Output is correct
3 Correct 7 ms 14408 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14388 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14368 KB Output is correct
13 Correct 8 ms 14292 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 7 ms 14420 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 7 ms 14408 KB Output is correct
19 Correct 7 ms 14420 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 15320 KB Output is correct
2 Correct 136 ms 15316 KB Output is correct
3 Correct 185 ms 15292 KB Output is correct
4 Correct 13 ms 15240 KB Output is correct
5 Incorrect 13 ms 15316 KB 3rd lines differ - on the 854th token, expected: '1', found: '0'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15148 KB Output is correct
2 Correct 13 ms 15188 KB Output is correct
3 Correct 13 ms 15316 KB Output is correct
4 Correct 16 ms 15316 KB Output is correct
5 Correct 13 ms 15236 KB Output is correct
6 Correct 13 ms 15316 KB Output is correct
7 Correct 13 ms 15188 KB Output is correct
8 Correct 12 ms 15292 KB Output is correct
9 Correct 13 ms 15208 KB Output is correct
10 Correct 13 ms 15244 KB Output is correct
11 Correct 13 ms 15256 KB Output is correct
12 Correct 17 ms 15316 KB Output is correct
13 Correct 13 ms 15340 KB Output is correct
14 Correct 12 ms 15148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 15344 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 10 ms 14932 KB Output is correct
2 Correct 11 ms 14932 KB Output is correct
3 Correct 11 ms 14908 KB Output is correct
4 Correct 10 ms 15004 KB Output is correct
5 Correct 10 ms 15024 KB Output is correct
6 Correct 10 ms 14984 KB Output is correct
7 Correct 11 ms 14992 KB Output is correct
8 Correct 10 ms 14932 KB Output is correct
9 Correct 11 ms 14920 KB Output is correct
10 Correct 12 ms 14932 KB Output is correct
11 Correct 10 ms 14932 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14304 KB Output is correct
14 Correct 7 ms 14408 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 7 ms 14420 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 7 ms 14388 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
21 Correct 7 ms 14420 KB Output is correct
22 Correct 7 ms 14420 KB Output is correct
23 Correct 7 ms 14368 KB Output is correct
24 Correct 8 ms 14292 KB Output is correct
25 Correct 8 ms 14420 KB Output is correct
26 Correct 7 ms 14420 KB Output is correct
27 Correct 7 ms 14420 KB Output is correct
28 Correct 7 ms 14420 KB Output is correct
29 Correct 7 ms 14408 KB Output is correct
30 Correct 7 ms 14420 KB Output is correct
31 Correct 7 ms 14420 KB Output is correct
32 Correct 73 ms 15320 KB Output is correct
33 Correct 136 ms 15316 KB Output is correct
34 Correct 185 ms 15292 KB Output is correct
35 Correct 13 ms 15240 KB Output is correct
36 Incorrect 13 ms 15316 KB 3rd lines differ - on the 854th token, expected: '1', found: '0'
37 Halted 0 ms 0 KB -