답안 #547474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547474 2022-04-10T20:07:01 Z blue 장난감 기차 (IOI17_train) C++17
11 / 100
10 ms 1632 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;
				}
			}
		}
	}


	while(1)
	{
		queue<int> tbv;
		int oldsize = 0;

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

		deg = vi(n, 0);
		for(int j = 0; j < m; j++)
			deg[U[j]]++;

		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] == 0)
				{
					pushed[v] = 1;
					tbv.push(v);
					good[v] = 0;
				}
				else
				{
					deg[v]--;
					if(deg[v] == 0)
					{
						pushed[v] = 1;
						tbv.push(v);
						good[v] = 0;
					}
				}
			}
		}

		int newsize = 0;
		for(int i = 0; i < n; i++)
			newsize += !good[i];

		if(newsize == oldsize) break;
	}

	return good;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1108 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB 3rd lines differ - on the 4th token, expected: '0', found: '1'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1364 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1236 KB Output is correct
2 Correct 7 ms 1492 KB Output is correct
3 Correct 9 ms 1620 KB Output is correct
4 Correct 10 ms 1560 KB Output is correct
5 Correct 8 ms 1620 KB Output is correct
6 Correct 7 ms 1620 KB Output is correct
7 Correct 8 ms 1628 KB Output is correct
8 Correct 9 ms 1492 KB Output is correct
9 Correct 7 ms 1492 KB Output is correct
10 Correct 7 ms 1628 KB Output is correct
11 Correct 8 ms 1620 KB Output is correct
12 Correct 8 ms 1620 KB Output is correct
13 Correct 8 ms 1632 KB Output is correct
14 Correct 8 ms 1464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1364 KB Output is correct
2 Correct 9 ms 1432 KB Output is correct
3 Correct 8 ms 1392 KB Output is correct
4 Correct 7 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 852 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1108 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -