답안 #409773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
409773 2021-05-21T13:32:32 Z Jasiekstrz 장난감 기차 (IOI17_train) C++17
5 / 100
719 ms 1612 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];
bool vis[N+10][2];
bool dp[N+10][2];
bool win[N+10];
int g[N+10];
vector<int> st={-1};
void dfs(int x,bool t)
{
	vis[x][t]=true;
	if(charge[x] && !t)
	{
		if(!vis[x][1])
			dfs(x,1);
		dp[x][0]=dp[x][1];
		return;
	}
	g[x]=st.size();
	st.push_back(x);
	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();
	//cerr<<x<<" "<<t<<" "<<dp[x][t]<<"\n";
	return;
}
void dfsw(int x,int fch)
{
	vis[x][0]=true;
	g[x]=st.size();
	st.push_back(x);
	if(charge[x])
		fch=g[x];
	bool sm=false;
	for(auto v:e[x])
	{
		if(g[v]!=0)
		{
			if(g[v]>fch && !ab[x])
				sm=true;
		}
		else
		{
			if(!vis[v][0])
				dfsw(v,fch);
			if(win[v]==ab[x])
				sm=true;
		}
	}
	if(!win[x])
		win[x]=(sm ? ab[x]:!ab[x]);
	g[x]=0;
	st.pop_back();
	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]);
	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];
		//cerr<<"win: "<<win[i]<<"\n";
	}
	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])
			dfsw(i,0);
	}
	vector<int> ans(n);
	for(int i=0;i<n;i++)
		ans[i]=win[i];
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1228 KB Output is correct
2 Correct 20 ms 1144 KB Output is correct
3 Correct 18 ms 972 KB Output is correct
4 Correct 17 ms 844 KB Output is correct
5 Correct 17 ms 876 KB Output is correct
6 Correct 17 ms 884 KB Output is correct
7 Correct 17 ms 872 KB Output is correct
8 Correct 18 ms 880 KB Output is correct
9 Correct 17 ms 844 KB Output is correct
10 Correct 17 ms 976 KB Output is correct
11 Correct 17 ms 840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 416 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB 3rd lines differ - on the 6th token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 1612 KB Output is correct
2 Correct 68 ms 1516 KB Output is correct
3 Correct 25 ms 1484 KB Output is correct
4 Correct 22 ms 1484 KB Output is correct
5 Correct 170 ms 1476 KB Output is correct
6 Incorrect 719 ms 1352 KB 3rd lines differ - on the 200th token, expected: '1', found: '0'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1196 KB Output is correct
2 Incorrect 21 ms 1156 KB 3rd lines differ - on the 458th token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 603 ms 1452 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1228 KB Output is correct
2 Correct 20 ms 1144 KB Output is correct
3 Correct 18 ms 972 KB Output is correct
4 Correct 17 ms 844 KB Output is correct
5 Correct 17 ms 876 KB Output is correct
6 Correct 17 ms 884 KB Output is correct
7 Correct 17 ms 872 KB Output is correct
8 Correct 18 ms 880 KB Output is correct
9 Correct 17 ms 844 KB Output is correct
10 Correct 17 ms 976 KB Output is correct
11 Correct 17 ms 840 KB Output is correct
12 Correct 1 ms 416 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Incorrect 1 ms 332 KB 3rd lines differ - on the 6th token, expected: '0', found: '1'
15 Halted 0 ms 0 KB -