답안 #547484

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

const int mx = 5'000;

vi edge[mx];
vi revedge[mx];

int n, m;
vi a, r;

vi getforced(vi active, vi good, int player)
{
	// cerr << "\n\n\n\nCALLED\n";
	vi deg(n, 0);
	for(int i = 0; i < n; i++)
	{
		if(!active[i]) continue;
		for(int j : edge[i])
		{
			if(active[j])
				deg[i]++;
		}
	}

	queue<int> tbv;
	for(int i = 0; i < n; i++)
	{
		// cerr << i << " -> " << active[i] << ' ' << good[i] << '\n';
		if(active[i] && good[i])
		{
			tbv.push(i);
		}
	}

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

		for(int v : revedge[u])
		{
			if(!active[v]) continue;
			if(good[v]) continue;

			// cerr << v << " : " << a[v] << ' ' << player << '\n';

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

	return good;
}


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


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


	vi active(n, 1);

	while(1)
	{
		// cerr << "it\n";
		int oldcount = 0;
		for(int i = 0; i < n; i++) oldcount += active[i];

		vi stations(n, 0);
		for(int i = 0; i < n; i++) stations[i] = active[i] && r[i];

		// cerr << "stations = ";
		// cerr << stations[0] << ' ' << stations[1] << '\n';


		vi Areach = getforced(active, stations, 1);

		// cerr << "Areach = ";
		// cerr << Areach[0] << ' ' << Areach[1] << '\n';

		vi nonAreach(n);
		for(int i = 0; i < n; i++)
		{
			if(!active[i])
				nonAreach[i] = 0;
			else
				nonAreach[i] = !Areach[i];
		}
		// cerr << nonAreach[0] << ' ' << nonAreach[1] << '\n';

		vi Breach = getforced(active, nonAreach, 0);

		for(int i = 0; i < n; i++)
			if(Breach[i])
				active[i] = 0;

		// cerr << Breach[0] << ' ' << Breach[1] << '\n';

		int newcount = 0;
		for(int i = 0; i < n; i++) newcount += active[i];

		// cerr << oldcount << " : " << newcount << '\n';

		// for(int i = 0; i < n; i++) cerr << active[i] << ' ';
		// 	cerr << '\n';

		if(oldcount == newcount) break;
	}

	return active;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1236 KB Output is correct
2 Correct 6 ms 1236 KB Output is correct
3 Correct 7 ms 1192 KB Output is correct
4 Correct 7 ms 1200 KB Output is correct
5 Correct 7 ms 1196 KB Output is correct
6 Correct 5 ms 1188 KB Output is correct
7 Correct 6 ms 1236 KB Output is correct
8 Correct 5 ms 1284 KB Output is correct
9 Correct 7 ms 1236 KB Output is correct
10 Correct 5 ms 1220 KB Output is correct
11 Correct 5 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 536 KB Output is correct
6 Correct 1 ms 540 KB Output is correct
7 Correct 1 ms 544 KB Output is correct
8 Correct 1 ms 548 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 544 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 544 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 1692 KB Output is correct
2 Correct 268 ms 1764 KB Output is correct
3 Correct 367 ms 1760 KB Output is correct
4 Correct 11 ms 1748 KB Output is correct
5 Correct 12 ms 1748 KB Output is correct
6 Correct 10 ms 1736 KB Output is correct
7 Correct 9 ms 1712 KB Output is correct
8 Correct 7 ms 1620 KB Output is correct
9 Correct 7 ms 1708 KB Output is correct
10 Correct 9 ms 1688 KB Output is correct
11 Correct 7 ms 1576 KB Output is correct
12 Correct 8 ms 1596 KB Output is correct
13 Correct 12 ms 1692 KB Output is correct
14 Correct 8 ms 1748 KB Output is correct
15 Correct 9 ms 1704 KB Output is correct
16 Correct 8 ms 1748 KB Output is correct
17 Correct 10 ms 1744 KB Output is correct
18 Correct 434 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1492 KB Output is correct
2 Correct 8 ms 1580 KB Output is correct
3 Correct 9 ms 1620 KB Output is correct
4 Correct 8 ms 1620 KB Output is correct
5 Correct 8 ms 1620 KB Output is correct
6 Correct 8 ms 1696 KB Output is correct
7 Correct 8 ms 1792 KB Output is correct
8 Correct 8 ms 1580 KB Output is correct
9 Correct 7 ms 1620 KB Output is correct
10 Correct 8 ms 1748 KB Output is correct
11 Correct 8 ms 1736 KB Output is correct
12 Correct 7 ms 1748 KB Output is correct
13 Correct 8 ms 1700 KB Output is correct
14 Correct 8 ms 1544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1620 KB Output is correct
2 Correct 8 ms 1740 KB Output is correct
3 Correct 9 ms 1740 KB Output is correct
4 Correct 7 ms 1620 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 4 ms 1236 KB Output is correct
7 Correct 5 ms 1236 KB Output is correct
8 Correct 6 ms 1236 KB Output is correct
9 Correct 5 ms 1188 KB Output is correct
10 Correct 2 ms 684 KB Output is correct
11 Correct 5 ms 1184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1236 KB Output is correct
2 Correct 6 ms 1236 KB Output is correct
3 Correct 7 ms 1192 KB Output is correct
4 Correct 7 ms 1200 KB Output is correct
5 Correct 7 ms 1196 KB Output is correct
6 Correct 5 ms 1188 KB Output is correct
7 Correct 6 ms 1236 KB Output is correct
8 Correct 5 ms 1284 KB Output is correct
9 Correct 7 ms 1236 KB Output is correct
10 Correct 5 ms 1220 KB Output is correct
11 Correct 5 ms 1236 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 536 KB Output is correct
17 Correct 1 ms 540 KB Output is correct
18 Correct 1 ms 544 KB Output is correct
19 Correct 1 ms 548 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 544 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 544 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 137 ms 1692 KB Output is correct
33 Correct 268 ms 1764 KB Output is correct
34 Correct 367 ms 1760 KB Output is correct
35 Correct 11 ms 1748 KB Output is correct
36 Correct 12 ms 1748 KB Output is correct
37 Correct 10 ms 1736 KB Output is correct
38 Correct 9 ms 1712 KB Output is correct
39 Correct 7 ms 1620 KB Output is correct
40 Correct 7 ms 1708 KB Output is correct
41 Correct 9 ms 1688 KB Output is correct
42 Correct 7 ms 1576 KB Output is correct
43 Correct 8 ms 1596 KB Output is correct
44 Correct 12 ms 1692 KB Output is correct
45 Correct 8 ms 1748 KB Output is correct
46 Correct 9 ms 1704 KB Output is correct
47 Correct 8 ms 1748 KB Output is correct
48 Correct 10 ms 1744 KB Output is correct
49 Correct 434 ms 1272 KB Output is correct
50 Correct 7 ms 1492 KB Output is correct
51 Correct 8 ms 1580 KB Output is correct
52 Correct 9 ms 1620 KB Output is correct
53 Correct 8 ms 1620 KB Output is correct
54 Correct 8 ms 1620 KB Output is correct
55 Correct 8 ms 1696 KB Output is correct
56 Correct 8 ms 1792 KB Output is correct
57 Correct 8 ms 1580 KB Output is correct
58 Correct 7 ms 1620 KB Output is correct
59 Correct 8 ms 1748 KB Output is correct
60 Correct 8 ms 1736 KB Output is correct
61 Correct 7 ms 1748 KB Output is correct
62 Correct 8 ms 1700 KB Output is correct
63 Correct 8 ms 1544 KB Output is correct
64 Correct 11 ms 1620 KB Output is correct
65 Correct 8 ms 1740 KB Output is correct
66 Correct 9 ms 1740 KB Output is correct
67 Correct 7 ms 1620 KB Output is correct
68 Correct 1 ms 596 KB Output is correct
69 Correct 4 ms 1236 KB Output is correct
70 Correct 5 ms 1236 KB Output is correct
71 Correct 6 ms 1236 KB Output is correct
72 Correct 5 ms 1188 KB Output is correct
73 Correct 2 ms 684 KB Output is correct
74 Correct 5 ms 1184 KB Output is correct
75 Correct 207 ms 1704 KB Output is correct
76 Correct 296 ms 1764 KB Output is correct
77 Correct 406 ms 1756 KB Output is correct
78 Correct 402 ms 1760 KB Output is correct
79 Correct 402 ms 1748 KB Output is correct
80 Correct 10 ms 1748 KB Output is correct
81 Correct 8 ms 1748 KB Output is correct
82 Correct 10 ms 1748 KB Output is correct
83 Correct 9 ms 1744 KB Output is correct
84 Correct 11 ms 1680 KB Output is correct
85 Correct 9 ms 1616 KB Output is correct
86 Correct 10 ms 1708 KB Output is correct
87 Correct 8 ms 1708 KB Output is correct
88 Correct 12 ms 1620 KB Output is correct
89 Correct 9 ms 1748 KB Output is correct
90 Correct 16 ms 1620 KB Output is correct
91 Correct 15 ms 1708 KB Output is correct
92 Correct 29 ms 1740 KB Output is correct
93 Correct 28 ms 1656 KB Output is correct
94 Correct 29 ms 1620 KB Output is correct
95 Correct 33 ms 1740 KB Output is correct
96 Correct 93 ms 1616 KB Output is correct
97 Correct 468 ms 1748 KB Output is correct
98 Correct 684 ms 1696 KB Output is correct
99 Correct 716 ms 1684 KB Output is correct
100 Correct 415 ms 1372 KB Output is correct