Submission #596142

# Submission time Handle Problem Language Result Execution time Memory
596142 2022-07-14T12:14:16 Z kshitij_sodani Toy Train (IOI17_train) C++14
38 / 100
2000 ms 1484 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define a first
#define b second
#define pb push_back
#define endl '\n'


#include "train.h"
vector<int> adj[5001];
vector<int> adj2[5001];

int co[5001];
int vis[5001];
std::vector<int> who_wins(std::vector<int> aa, std::vector<int> bb, std::vector<int> u, std::vector<int> v) {
	int n=aa.size();
	for(int i=0;i<u.size();i++){
		adj[u[i]].pb(v[i]);
		adj2[v[i]].pb(u[i]);
	}
	int ind=-1;
	vector<int> ss;
	for(int i=0;i<n;i++){
		if(bb[i]==1){
			ind=i;
			ss.pb(ind);
		}
	}
	vector<int> cc=bb;

	while(true){
		vector<int> ss;
		queue<int> tt;
		for(int i=0;i<n;i++){
			co[i]=adj[i].size();
			if(cc[i]==1){
				ind=i;
				tt.push(i);
				ss.pb(ind);
				vis[i]=1;
			}
			else{
				vis[i]=0;
			}
		}
		bb=cc;
		while(tt.size()){
			int no=tt.front();
			tt.pop();
			int st=1;
			for(auto j:adj2[no]){
				if(vis[j]==0){
					if(aa[j]==1){
						vis[j]=1;
						bb[j]=1;
						tt.push(j);
					}
					else{
						co[j]--;
						if(co[j]==0){
							vis[j]=1;
							bb[j]=1;
							tt.push(j);
						}
					}
				}
			}

			for(int i=0;i<n;i++){
				if(bb[i]==0){
					int su=0;
					for(auto j:adj[i]){
						su+=bb[j];
					}
					if(aa[i]==1){
						if(su>0){
							bb[i]=1;
							st=0;
						}
					}
					else{
						if(su==adj[i].size()){
							bb[i]=1;
							st=0;
						}
					}
				}
			}
			if(st==1){
				break;
			}
		}
		int st=1;
		for(auto j:ss){
			int su=0;
			for(auto jj:adj[j]){
				su+=bb[jj];
			}
			if(aa[j]==1){
				if(su==0){
					st=0;
					cc[j]=0;
					break;
				}
			}
			else{
				if(su<adj[j].size()){
					st=0;
					cc[j]=0;
					cc[j]=0;
				}
			}
		}
		if(st==1){
			break;
		}
	}
	
	
	return bb;
	/*for(auto j:adj[ind]){
		if(bb[j]==1){
			for(int i=0;i<n;i++){
				if(bb[i]==1){
					ans[i]=1;
				}
			}
			break;
		}
	}
	return ans;*/
}

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:18:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for(int i=0;i<u.size();i++){
      |              ~^~~~~~~~~
train.cpp:83:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |       if(su==adj[i].size()){
      |          ~~^~~~~~~~~~~~~~~
train.cpp:108:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     if(su<adj[j].size()){
      |        ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 87 ms 1136 KB Output is correct
2 Correct 96 ms 1108 KB Output is correct
3 Correct 90 ms 1128 KB Output is correct
4 Correct 116 ms 1124 KB Output is correct
5 Correct 92 ms 1116 KB Output is correct
6 Correct 86 ms 1116 KB Output is correct
7 Correct 7 ms 1108 KB Output is correct
8 Correct 36 ms 1108 KB Output is correct
9 Correct 81 ms 1116 KB Output is correct
10 Correct 42 ms 1084 KB Output is correct
11 Correct 4 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2086 ms 1412 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1236 KB Output is correct
2 Correct 8 ms 1316 KB Output is correct
3 Correct 9 ms 1388 KB Output is correct
4 Correct 9 ms 1448 KB Output is correct
5 Correct 46 ms 1364 KB Output is correct
6 Correct 76 ms 1376 KB Output is correct
7 Correct 42 ms 1376 KB Output is correct
8 Correct 10 ms 1364 KB Output is correct
9 Correct 7 ms 1364 KB Output is correct
10 Correct 7 ms 1364 KB Output is correct
11 Correct 7 ms 1484 KB Output is correct
12 Correct 8 ms 1364 KB Output is correct
13 Correct 9 ms 1364 KB Output is correct
14 Correct 8 ms 1332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1364 KB Output is correct
2 Correct 7 ms 1364 KB Output is correct
3 Correct 7 ms 1376 KB Output is correct
4 Correct 6 ms 1236 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 4 ms 1108 KB Output is correct
8 Correct 4 ms 1108 KB Output is correct
9 Correct 4 ms 1108 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 5 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 1136 KB Output is correct
2 Correct 96 ms 1108 KB Output is correct
3 Correct 90 ms 1128 KB Output is correct
4 Correct 116 ms 1124 KB Output is correct
5 Correct 92 ms 1116 KB Output is correct
6 Correct 86 ms 1116 KB Output is correct
7 Correct 7 ms 1108 KB Output is correct
8 Correct 36 ms 1108 KB Output is correct
9 Correct 81 ms 1116 KB Output is correct
10 Correct 42 ms 1084 KB Output is correct
11 Correct 4 ms 1108 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 0 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 0 ms 468 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 0 ms 468 KB Output is correct
32 Execution timed out 2086 ms 1412 KB Time limit exceeded
33 Halted 0 ms 0 KB -