Submission #641135

# Submission time Handle Problem Language Result Execution time Memory
641135 2022-09-16T04:53:12 Z ggoh Toy Train (IOI17_train) C++14
0 / 100
2000 ms 1492 KB
#include "train.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(v) ((int)(v).size())
 
int n,m,dif,ch[5005],out[5005];
vector<int>G[5005],rev[5005];
vector<int>A,R,T;
void f(int p)
{
	queue<int>Q;
	if(p==1)
	{
		for(int i=0;i<n;i++)
		{
			if(ch[i])Q.push(i);
			out[i]=sz(G[i]);
		}
		while(!Q.empty())
		{
			int q=Q.front();Q.pop();
			for(auto &k:rev[q])
			{
				out[k]--;
				if(!ch[k])
				{
					if(A[k] || out[k]==0)
					{
						ch[k]=1;
						Q.push(k);
					}
				}
			}
		}
	}
	else
	{
		for(int i=0;i<n;i++)
		{
			if(!ch[i])Q.push(i);
			out[i]=sz(G[i]);
		}
		while(!Q.empty())
		{
			int q=Q.front();Q.pop();
			for(auto &k:rev[q])
			{
				out[k]--;
				if(ch[k])
				{
					if(!A[k] || out[k]==0)
					{
						ch[k]=0;
						Q.push(k);
						dif=1;
					}
				}
			}
		}
	}
}
void g()
{
	while(1)
	{
		f(0);
		if(!dif)break;
		for(int i=0;i<n;i++)if(!R[i])ch[i]=0;
		f(1);
	}
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
	n=sz(a);m=sz(u);
	vector<int> res(n);
	A=a;R=r;
	for(int i=0;i<m;i++)
	{
		G[u[i]].push_back(v[i]);
		rev[v[i]].push_back(u[i]);
	}
	for(int i=0;i<n;i++)ch[i]=R[i];
	f(1);
	g();
	for(int i=0;i<n;i++)res[i]=ch[i];
	return res;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 2069 ms 1108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2081 ms 468 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2065 ms 1492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2080 ms 1236 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1364 KB Output is correct
2 Correct 11 ms 1348 KB Output is correct
3 Correct 11 ms 1388 KB Output is correct
4 Correct 8 ms 1364 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Execution timed out 2075 ms 980 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2069 ms 1108 KB Time limit exceeded
2 Halted 0 ms 0 KB -