Submission #547475

# Submission time Handle Problem Language Result Execution time Memory
547475 2022-04-10T20:18:29 Z blue Toy Train (IOI17_train) C++17
11 / 100
10 ms 1492 KB
#include "train.h"
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
using namespace std;

using vi = vector<int>;
#define sz(x) int(x.size())


 //a = owner, r = charging
vi who_wins(vi a, vi r, vi U, vi V) 
{
	int n = sz(a);
	int m = sz(U);

	vi edge[n];
	vi revedge[n];
	for(int j = 0; j < m; j++)
	{
		edge[U[j]].push_back(V[j]);
		revedge[V[j]].push_back(U[j]);
	}



	vi good(n, 0);
	vi pushed(n, 0);

	queue<int> tbv;

	for(int i = 0; i < n; i++)
	{
		if(r[i])
		{
			good[i] = 1;
			tbv.push(i);
			pushed[i] = 1;
		}
	}

	vi deg(n, 0);
	for(int j = 0; j < m; j++)
		deg[U[j]]++;
	// cerr << "done\n";

	while(!tbv.empty())
	{
		int u = tbv.front();
		tbv.pop();
		// cerr << "u = " << u << '\n';

		for(int v : revedge[u])
		{
			if(pushed[v]) continue;

			if(a[v] == 1)
			{
				pushed[v] = 1;
				tbv.push(v);
				good[v] = 1;
			}
			else
			{
				deg[v]--;
				if(deg[v] == 0)
				{
					pushed[v] = 1;
					tbv.push(v);
					good[v] = 1;
				}
			}
		}
	}

	// cerr << "checked\n";


	while(1)
	{
		bool newreached = 0;

		for(int i = 0; i < n; i++)
		{
			if(!good[i]) continue;

			if(a[i] == 0)
			{
				good[i] = 1;
				for(int j : edge[i])
				{
					if(!good[j])
						good[i] = 0;
				}
			}
			else
			{
				good[i] = 0;
				for(int j : edge[i])
				{
					if(good[j])
						good[i] = 1;
				}
			}

			if(!good[i]) newreached = 1;
		}


		if(!newreached) break;
	}

	return good;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 980 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 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 216 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 256 KB 3rd lines differ - on the 3rd token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1364 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1236 KB Output is correct
2 Correct 7 ms 1236 KB Output is correct
3 Correct 8 ms 1384 KB Output is correct
4 Correct 9 ms 1364 KB Output is correct
5 Correct 9 ms 1400 KB Output is correct
6 Correct 10 ms 1384 KB Output is correct
7 Correct 9 ms 1364 KB Output is correct
8 Correct 7 ms 1364 KB Output is correct
9 Correct 7 ms 1236 KB Output is correct
10 Correct 7 ms 1388 KB Output is correct
11 Correct 7 ms 1492 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 8 ms 1392 KB Output is correct
14 Correct 7 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1364 KB Output is correct
2 Correct 7 ms 1364 KB Output is correct
3 Correct 7 ms 1364 KB Output is correct
4 Correct 6 ms 1236 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 4 ms 980 KB Output is correct
7 Correct 4 ms 824 KB Output is correct
8 Incorrect 5 ms 852 KB 3rd lines differ - on the 5th token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 980 KB 3rd lines differ - on the 14th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -