Submission #1240152

#TimeUsernameProblemLanguageResultExecution timeMemory
1240152Zbyszek99Toy Train (IOI17_train)C++20
100 / 100
531 ms1820 KiB
#include "train.h"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vl vector<long long>
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace std;
//mt19937 mt;void random(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll rand(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

vi ans;
vector<pii> graph_in[5001];
vector<pii> graph_out[5001];
bool is_bat[5001];
bool odw[5001];
bool type[5001];
int cnt[5001];
bool was_cnt[200001];
int m;

bool solve(int n)
{
	rep(i,m) was_cnt[i] = 0;
	queue<int> q;
	rep(i,n)
	{
		ans[i] = 0;
		cnt[i] = 1;
		if(type[i] == 0) cnt[i] = siz(graph_out[i]);
		odw[i] = 0;
		forall(it,graph_out[i])
		{
			if(is_bat[it.ff]) 
			{
				was_cnt[it.ss] = 1;
				cnt[i]--;
			}
		}
		if(cnt[i] <= 0) q.push(i);
	}
	while(!q.empty())
	{
		int t = q.front();
		q.pop();
		if(odw[t]) continue;
		odw[t] = 1;
		ans[t] = 1;
		forall(it,graph_in[t])
		{
			if(type[it.ff] == 1)
			{
				q.push(it.ff);
			}
			else
			{
				if(was_cnt[it.ss]) continue;
				was_cnt[it.ss] = 1;
				cnt[it.ff]--;
				if(cnt[it.ff] == 0) q.push(it.ff);
			}
		}
	}
	bool was = 1;
	rep(i,n)
	{
		if(is_bat[i] && ans[i] == 0)
		{
			is_bat[i] = 0;
			was = 0;
		}
	}
	return was;
}

vi who_wins(vi a, vi r, vi u, vi v) 
{
	m = siz(u);
	int n = siz(a);
	ans.resize(n);
	rep(i,n) is_bat[i] = r[i];
	rep(i,n) type[i] = a[i];
	rep(i,siz(u))
	{
		graph_out[u[i]].pb({v[i],i});
		graph_in[v[i]].pb({u[i],i});
	}
	while(!solve(n));
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...