Submission #282336

# Submission time Handle Problem Language Result Execution time Memory
282336 2020-08-24T10:18:21 Z MohamedAhmed04 Toy Train (IOI17_train) C++14
5 / 100
2000 ms 1540 KB
#include <bits/stdc++.h>
#include "train.h"
//#include "grader.cpp"

using namespace std ;

const int MAX = 5010 ;

int A[MAX] , R[MAX] ;
vector< vector<int> >adj(MAX) ;
int n ;

int vis[MAX] , mark[MAX] , prv[MAX] ;

bool dfs(int node)
{
	vis[node] = 1 , mark[node] = 1 ;
	for(auto &child : adj[node])
	{
		if(vis[child])
		{
			if(mark[child])
			{
				int a = node ;
				bool flag = 0 ;
				while(a != child)
				{
					flag |= R[a] ;
					a = prv[a] ;
				}
				flag |= R[a] ;
				if(flag == A[node])
				{
					mark[node] = 0 ;
					return 1 ;
				}
			}
			continue ;
		}
		prv[child] = node ;
		bool t = dfs(child) ;
		if(A[node] && A[child] == t)
		{
			mark[node] = 0 ;
			return 1 ;
		}
		else if(!A[node] && A[child] != t)
		{
			mark[node] = 0 ;
			return 1 ;
		}
	}
	mark[node] = 0 ;
	return 0 ;
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) 
{
	n = a.size() ;
	int m = u.size() ;
	for(int i = 1 ; i <= n ; ++i)
	{
		A[i] = a[i-1] ;
		R[i] = r[i-1] ;
	}
	for(int i = 0 ; i < m ; ++i)
		adj[u[i] + 1].push_back(v[i] + 1) ;
	vector<int>ans ;
	for(int i = 1 ; i <= n ; ++i)
	{
		memset(vis , 0 , sizeof(vis)) ;
		bool t = dfs(i) ;
		if(A[i] == t)
			ans.push_back(1) ;
		else
			ans.push_back(0) ;
	}
	return ans ;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 896 KB Output is correct
2 Correct 9 ms 896 KB Output is correct
3 Correct 9 ms 896 KB Output is correct
4 Correct 11 ms 896 KB Output is correct
5 Correct 9 ms 896 KB Output is correct
6 Correct 9 ms 904 KB Output is correct
7 Correct 10 ms 896 KB Output is correct
8 Correct 8 ms 896 KB Output is correct
9 Correct 8 ms 896 KB Output is correct
10 Correct 8 ms 896 KB Output is correct
11 Correct 7 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Incorrect 1 ms 512 KB 3rd lines differ - on the 3rd token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 240 ms 1540 KB Output is correct
2 Correct 230 ms 1528 KB Output is correct
3 Correct 228 ms 1400 KB Output is correct
4 Correct 22 ms 1152 KB Output is correct
5 Correct 639 ms 1480 KB Output is correct
6 Execution timed out 2059 ms 1220 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2091 ms 1152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2087 ms 1276 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 896 KB Output is correct
2 Correct 9 ms 896 KB Output is correct
3 Correct 9 ms 896 KB Output is correct
4 Correct 11 ms 896 KB Output is correct
5 Correct 9 ms 896 KB Output is correct
6 Correct 9 ms 904 KB Output is correct
7 Correct 10 ms 896 KB Output is correct
8 Correct 8 ms 896 KB Output is correct
9 Correct 8 ms 896 KB Output is correct
10 Correct 8 ms 896 KB Output is correct
11 Correct 7 ms 896 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Incorrect 1 ms 512 KB 3rd lines differ - on the 3rd token, expected: '1', found: '0'
16 Halted 0 ms 0 KB -