답안 #286384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
286384 2020-08-30T10:57:26 Z user202729 장난감 기차 (IOI17_train) C++17
100 / 100
1075 ms 1912 KB
// moreflags=grader.cpp
//
// 13
// 
#include "train.h"
#include<vector>
#if not LOCAL
#define NDEBUG
#endif
#include<cassert>
#include<algorithm>

std::vector<std::vector<int>> add, reverse;

std::vector<int> order;
std::vector<char> state;
void work(int node){
	assert(not state[node]); state[node]=true;
	for(auto other: add[node]) if(not state[other])
		work(other);
	order.push_back(node);
}

std::vector<int> component;
void work2(int node){
	assert(state[node]); state[node]=false;
	for(auto other: reverse[node]) if(state[other])
		work2(other);
	component.push_back(node);
}

std::vector<int> awin;
std::vector<bool> keep;
std::vector<int> outDegree;
std::vector<int> a;

void remove(int node){
	assert(keep[node]);
	keep[node]=false;
	for(auto other: reverse[node]) {
		--outDegree[other];
		assert(outDegree[other]>=0); assert(outDegree[other]<(int)add[other].size());
	}

	for(auto other: reverse[node]) if(keep[other]){
		if(a[other]){
			remove(other);
		}else{
			if(outDegree[other]==0)
				remove(other);
		}
	}
}

void remove2(int node){
	assert(keep[node]);
	keep[node]=false;
	for(auto other: reverse[node]) {
		--outDegree[other];
		assert(outDegree[other]>=0); assert(outDegree[other]<(int)add[other].size());
	}

	for(auto other: reverse[node]) if(keep[other]){
		if(a[other]){
			if(outDegree[other]==0)
				remove2(other);
		}else{
			remove2(other);
		}
	}
}

std::vector<int> who_wins(std::vector<int> a_, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	::a=std::move(a_);
	add.clear(); reverse.clear();
	add.resize(a.size());
	reverse.resize(a.size());
	for(int index=0; index<(int)u.size(); ++index){
		auto const first=u[index], sec=v[index];
		add[first].push_back(sec); reverse[sec].push_back(first);
	}
 
	awin.assign(a.size(), true);

	bool useful;
	do{
		useful=false;
		/*
		for(int mask=noChargeMask; mask; mask=(mask-1)&noChargeMask){
			for(int node=0; node<(int)a.size(); ++node)
				if(mask>>node&1){
					if(a[node]){
						if(not contains(mask|bwin, adjacent[node]))
							goto next_mask;
					}else{
						if(((mask|bwin)&adjacent[node])==0)
							goto next_mask;
					}
				}
			bwin|=mask;
next_mask:;
		}
 
		for(int node=0; node<(int)a.size(); ++node)
			if(a[node]){
				if(contains(bwin, adjacent[node])) bwin|=1<<node;
			}else{
				if((bwin&adjacent[node])!=0) bwin|=1<<node;
			}
			*/

		keep.assign(a.size(), true);

		outDegree.resize(a.size());
		for(int node=0; node<(int)a.size(); ++node){
			outDegree[node]=(int)add[node].size();
		}

		for(int node=0; node<(int)add.size(); ++node)
			if(keep[node] and r[node] and awin[node])
				remove(node);

		for(int node=0; node<(int)add.size(); ++node){
			if(not awin[node]) assert(keep[node]);
			if(awin[node] and keep[node]){
				useful=true;
				awin[node]=false;
			}
		}

		// ======

		keep.assign(a.size(), true);

		outDegree.resize(a.size());
		for(int node=0; node<(int)a.size(); ++node){
			outDegree[node]=(int)add[node].size();
		}

		for(int node=0; node<(int)add.size(); ++node)
			if(keep[node] and not awin[node])
				remove2(node);

		for(int node=0; node<(int)add.size(); ++node){
			if(not awin[node]) assert(not keep[node]);
			if(awin[node] and not keep[node]){
				useful=true;
				awin[node]=false;
			}
		}
	}while(useful);
 
	return std::move(awin);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 7 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 7 ms 1152 KB Output is correct
5 Correct 6 ms 1152 KB Output is correct
6 Correct 6 ms 1152 KB Output is correct
7 Correct 5 ms 1152 KB Output is correct
8 Correct 6 ms 1152 KB Output is correct
9 Correct 6 ms 1152 KB Output is correct
10 Correct 5 ms 1152 KB Output is correct
11 Correct 5 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 1792 KB Output is correct
2 Correct 281 ms 1828 KB Output is correct
3 Correct 426 ms 1912 KB Output is correct
4 Correct 11 ms 1664 KB Output is correct
5 Correct 11 ms 1664 KB Output is correct
6 Correct 13 ms 1664 KB Output is correct
7 Correct 10 ms 1536 KB Output is correct
8 Correct 10 ms 1664 KB Output is correct
9 Correct 10 ms 1536 KB Output is correct
10 Correct 10 ms 1536 KB Output is correct
11 Correct 11 ms 1536 KB Output is correct
12 Correct 10 ms 1536 KB Output is correct
13 Correct 10 ms 1664 KB Output is correct
14 Correct 10 ms 1664 KB Output is correct
15 Correct 10 ms 1664 KB Output is correct
16 Correct 11 ms 1664 KB Output is correct
17 Correct 16 ms 1664 KB Output is correct
18 Correct 704 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1408 KB Output is correct
2 Correct 11 ms 1536 KB Output is correct
3 Correct 11 ms 1536 KB Output is correct
4 Correct 13 ms 1664 KB Output is correct
5 Correct 11 ms 1664 KB Output is correct
6 Correct 10 ms 1536 KB Output is correct
7 Correct 10 ms 1536 KB Output is correct
8 Correct 10 ms 1536 KB Output is correct
9 Correct 10 ms 1536 KB Output is correct
10 Correct 11 ms 1664 KB Output is correct
11 Correct 11 ms 1664 KB Output is correct
12 Correct 11 ms 1664 KB Output is correct
13 Correct 11 ms 1664 KB Output is correct
14 Correct 10 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1664 KB Output is correct
2 Correct 10 ms 1664 KB Output is correct
3 Correct 11 ms 1664 KB Output is correct
4 Correct 9 ms 1536 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 6 ms 1152 KB Output is correct
7 Correct 10 ms 1024 KB Output is correct
8 Correct 7 ms 1024 KB Output is correct
9 Correct 7 ms 1024 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 6 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 7 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 7 ms 1152 KB Output is correct
5 Correct 6 ms 1152 KB Output is correct
6 Correct 6 ms 1152 KB Output is correct
7 Correct 5 ms 1152 KB Output is correct
8 Correct 6 ms 1152 KB Output is correct
9 Correct 6 ms 1152 KB Output is correct
10 Correct 5 ms 1152 KB Output is correct
11 Correct 5 ms 1152 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 0 ms 256 KB Output is correct
26 Correct 0 ms 256 KB Output is correct
27 Correct 0 ms 256 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 129 ms 1792 KB Output is correct
33 Correct 281 ms 1828 KB Output is correct
34 Correct 426 ms 1912 KB Output is correct
35 Correct 11 ms 1664 KB Output is correct
36 Correct 11 ms 1664 KB Output is correct
37 Correct 13 ms 1664 KB Output is correct
38 Correct 10 ms 1536 KB Output is correct
39 Correct 10 ms 1664 KB Output is correct
40 Correct 10 ms 1536 KB Output is correct
41 Correct 10 ms 1536 KB Output is correct
42 Correct 11 ms 1536 KB Output is correct
43 Correct 10 ms 1536 KB Output is correct
44 Correct 10 ms 1664 KB Output is correct
45 Correct 10 ms 1664 KB Output is correct
46 Correct 10 ms 1664 KB Output is correct
47 Correct 11 ms 1664 KB Output is correct
48 Correct 16 ms 1664 KB Output is correct
49 Correct 704 ms 1400 KB Output is correct
50 Correct 9 ms 1408 KB Output is correct
51 Correct 11 ms 1536 KB Output is correct
52 Correct 11 ms 1536 KB Output is correct
53 Correct 13 ms 1664 KB Output is correct
54 Correct 11 ms 1664 KB Output is correct
55 Correct 10 ms 1536 KB Output is correct
56 Correct 10 ms 1536 KB Output is correct
57 Correct 10 ms 1536 KB Output is correct
58 Correct 10 ms 1536 KB Output is correct
59 Correct 11 ms 1664 KB Output is correct
60 Correct 11 ms 1664 KB Output is correct
61 Correct 11 ms 1664 KB Output is correct
62 Correct 11 ms 1664 KB Output is correct
63 Correct 10 ms 1536 KB Output is correct
64 Correct 11 ms 1664 KB Output is correct
65 Correct 10 ms 1664 KB Output is correct
66 Correct 11 ms 1664 KB Output is correct
67 Correct 9 ms 1536 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 6 ms 1152 KB Output is correct
70 Correct 10 ms 1024 KB Output is correct
71 Correct 7 ms 1024 KB Output is correct
72 Correct 7 ms 1024 KB Output is correct
73 Correct 2 ms 512 KB Output is correct
74 Correct 6 ms 1024 KB Output is correct
75 Correct 180 ms 1664 KB Output is correct
76 Correct 284 ms 1792 KB Output is correct
77 Correct 424 ms 1792 KB Output is correct
78 Correct 460 ms 1824 KB Output is correct
79 Correct 441 ms 1912 KB Output is correct
80 Correct 11 ms 1572 KB Output is correct
81 Correct 12 ms 1664 KB Output is correct
82 Correct 13 ms 1664 KB Output is correct
83 Correct 11 ms 1664 KB Output is correct
84 Correct 12 ms 1664 KB Output is correct
85 Correct 12 ms 1664 KB Output is correct
86 Correct 14 ms 1664 KB Output is correct
87 Correct 12 ms 1536 KB Output is correct
88 Correct 16 ms 1664 KB Output is correct
89 Correct 12 ms 1536 KB Output is correct
90 Correct 21 ms 1536 KB Output is correct
91 Correct 21 ms 1652 KB Output is correct
92 Correct 35 ms 1656 KB Output is correct
93 Correct 33 ms 1632 KB Output is correct
94 Correct 38 ms 1644 KB Output is correct
95 Correct 38 ms 1644 KB Output is correct
96 Correct 98 ms 1556 KB Output is correct
97 Correct 634 ms 1648 KB Output is correct
98 Correct 920 ms 1656 KB Output is correct
99 Correct 1075 ms 1656 KB Output is correct
100 Correct 729 ms 1400 KB Output is correct