Submission #409660

# Submission time Handle Problem Language Result Execution time Memory
409660 2021-05-21T09:51:16 Z Jasiekstrz Toy Train (IOI17_train) C++17
0 / 100
893 ms 2136 KB
#include<bits/stdc++.h>
#include "train.h"
using namespace std;
const int N=5e3;
bool ab[N+10];
bool charge[N+10];
vector<int> e[N+10];
vector<int> e2[N+10];
bool vis[N+10][2];
bool dp[N+10][2];
bool win[N+10];
int d2[N+10];
int g[N+10];
vector<int> st;
void dfs(int x,bool t)
{
	vis[x][t]=true;
	g[x]=st.size();
	st.push_back(x);
	if(charge[x] && !t)
	{
		if(!vis[x][1])
			dfs(x,1);
		dp[x][0]=dp[x][1];
		return;
	}
	dp[x][t]=!ab[x];
	for(auto v:e[x])
	{
		if(g[v]==1)
		{
			if(ab[x]==t)
			{
				dp[x][t]=ab[x];
				break;
			}
			else
				continue;
		}
		else if(g[v]!=0)
		{
			if(!ab[x])
			{
				dp[x][t]=false;
				break;
			}
			else
				continue;
		}
		if(!vis[v][t])
			dfs(v,t);
		if(dp[v][t]==ab[x])
		{
			dp[x][t]=ab[x];
			break;
		}
	}
	g[x]=0;
	st.pop_back();
	return;
}
void dfsw(int x)
{
	win[x]=true;
	vis[x][0]=true;
	for(auto v:e2[x])
	{
		if(vis[v][0])
			continue;
		if(ab[v])
			dfsw(v);
		else if(d2[v]==1)
			dfsw(v);
		else
			d2[v]--;
	}
	return;
}
vector<int> who_wins(vector<int> a,vector<int> r,vector<int> u,vector<int> v)
{
	int n=a.size(),m=u.size();
	for(int i=0;i<n;i++)
	{
		ab[i]=a[i];
		charge[i]=r[i];
	}
	for(int i=0;i<m;i++)
	{
		e[u[i]].push_back(v[i]);
		e2[v[i]].push_back(u[i]);
		d2[v[i]]++;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
			vis[j][0]=vis[i][1]=false;
		dfs(i,0);
		win[i]=dp[i][0];
	}
	for(int i=0;i<n;i++)
		vis[i][0]=vis[i][1]=false;
	for(int i=0;i<n;i++)
	{
		if(!vis[i][0] && win[i])
			dfsw(i);
	}
	vector<int> ans(n);
	for(int i=0;i<n;i++)
		ans[i]=win[i];
	return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 1228 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 536 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 171 ms 2136 KB Output is correct
2 Correct 68 ms 1892 KB Output is correct
3 Correct 32 ms 1852 KB Output is correct
4 Incorrect 893 ms 1900 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1444 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 Incorrect 613 ms 1792 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 Incorrect 17 ms 1228 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -