Submission #56638

# Submission time Handle Problem Language Result Execution time Memory
56638 2018-07-12T04:18:13 Z Crown Toy Train (IOI17_train) C++14
11 / 100
23 ms 4952 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 5005;

vector<int> adj[maxn];
vector<int> rev[maxn];
vector<int> scc[maxn];
vector<int> scc_rev[maxn];
int has_charge[maxn];
int mark[maxn];
int scc_sz[maxn];

stack<int> s;
vector<bool> vis;
vector<int> comp;
vector<int> loop;

void dfs(int u)
{
	vis[u] = true;
	for(auto v : adj[u])
	{
		if(vis[v]) continue;
		dfs(v);
	}
	s.push(u);
}

int compcount = 0;

void dfs2(int u)
{
	vis[u] = true;
	for(auto v : rev[u])
	{
		if(vis[v]) continue;
		dfs2(v);
	}
	s.push(u);
	comp[u] = compcount;
	scc_sz[compcount]++;
}

void dfs3(int u)
{
	mark[u] = true;
	for(auto v : scc_rev[u])
	{
		if(mark[v]) continue;
		dfs3(v);
	}
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v)
{
	int n = a.size(); int m = u.size();
	loop.resize(n);
	for(int i = 0; i< m; i++)
	{
		adj[u[i]].pb(v[i]);
		rev[v[i]].pb(u[i]);
		if(u[i] == v[i]) 
			loop[u[i]] = true;
	}
	vis.assign(n, 0);
	for(int i = 0; i< n; i++) 
	{
		if(!vis[i]) dfs(i);
	}	
	comp.resize(n);
	vis.assign(n, 0);
	while(!s.empty())
	{
		int u = s.top(); s.pop();
		if(comp[u]) continue;
		compcount++;
		dfs2(u);
	}
	for(int u = 0; u< n; u++)
	{
		for(auto v : adj[u])
		{
			if(comp[u] == comp[v]) continue;
			scc[comp[u]].pb(comp[v]);
			scc_rev[comp[v]].pb(comp[u]);
		}
	}
	for(int u = 1; u<= compcount; u++)
	{
		sort(scc[u].begin(), scc[u].end());
		scc[u].resize(unique(scc[u].begin(), scc[u].end())-scc[u].begin());
		sort(scc_rev[u].begin(), scc_rev[u].end());
		scc_rev[u].resize(unique(scc_rev[u].begin(), scc_rev[u].end())-scc_rev[u].begin());
	}
	for(int u = 0; u< n; u++)
	{
		if(r[u] && (scc_sz[comp[u]]>= 2 || loop[u]))
		{
			has_charge[comp[u]] = true;
		}
	}
	vis.assign(n+1, 0);
	for(int u = 1; u<= compcount; u++)
	{
		if(has_charge[u] && !mark[u])
		{
			dfs3(u);
		}
	}
	vector<int> res(n);
	for(int u = 0; u< n; u++)
	{
		if(a[0])
			res[u] = mark[comp[u]];
		else 
			res[u] = 1-mark[comp[u]];
	}
	return res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1912 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 4 ms 1912 KB 3rd lines differ - on the 8th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2440 KB Output is correct
2 Correct 17 ms 2440 KB Output is correct
3 Correct 21 ms 2440 KB Output is correct
4 Correct 21 ms 2440 KB Output is correct
5 Correct 23 ms 2440 KB Output is correct
6 Correct 18 ms 2492 KB Output is correct
7 Correct 16 ms 2608 KB Output is correct
8 Correct 15 ms 2944 KB Output is correct
9 Correct 15 ms 3152 KB Output is correct
10 Correct 15 ms 3344 KB Output is correct
11 Correct 15 ms 3540 KB Output is correct
12 Correct 23 ms 3856 KB Output is correct
13 Correct 15 ms 4076 KB Output is correct
14 Correct 20 ms 4248 KB Output is correct
15 Correct 15 ms 4456 KB Output is correct
16 Correct 14 ms 4664 KB Output is correct
17 Correct 18 ms 4872 KB Output is correct
18 Correct 11 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 4952 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 12 ms 4952 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 11 ms 1912 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -