Submission #596135

# Submission time Handle Problem Language Result Execution time Memory
596135 2022-07-14T12:08:09 Z kshitij_sodani Toy Train (IOI17_train) C++14
33 / 100
2000 ms 1108 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];
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]);
	}
	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;
		for(int i=0;i<n;i++){
			if(cc[i]==1){
				ind=i;
				ss.pb(ind);
			}
		}
		bb=cc;
		while(true){
			int st=1;
			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;
							break;
						}
					}
					else{
						if(su==adj[i].size()){
							bb[i]=1;
							st=0;
							break;
						}
					}
				}
			}
			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:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i=0;i<u.size();i++){
      |              ~^~~~~~~~~
train.cpp:52:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |       if(su==adj[i].size()){
      |          ~~^~~~~~~~~~~~~~~
train.cpp:78:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     if(su<adj[j].size()){
      |        ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 2025 ms 724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 424 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2074 ms 980 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 980 KB Output is correct
2 Correct 109 ms 852 KB Output is correct
3 Correct 23 ms 980 KB Output is correct
4 Correct 28 ms 1108 KB Output is correct
5 Correct 101 ms 980 KB Output is correct
6 Correct 151 ms 1008 KB Output is correct
7 Correct 168 ms 1000 KB Output is correct
8 Correct 22 ms 980 KB Output is correct
9 Correct 6 ms 980 KB Output is correct
10 Correct 11 ms 1092 KB Output is correct
11 Correct 7 ms 1108 KB Output is correct
12 Correct 11 ms 1088 KB Output is correct
13 Correct 52 ms 1028 KB Output is correct
14 Correct 60 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 980 KB Output is correct
2 Correct 36 ms 1040 KB Output is correct
3 Correct 61 ms 980 KB Output is correct
4 Correct 57 ms 980 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 8 ms 852 KB Output is correct
8 Correct 6 ms 852 KB Output is correct
9 Correct 7 ms 872 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 6 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2025 ms 724 KB Time limit exceeded
2 Halted 0 ms 0 KB -