답안 #646611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646611 2022-09-30T10:10:27 Z jamezzz 장난감 기차 (IOI17_train) C++17
100 / 100
1086 ms 1888 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

#define maxn 5005
#define pb push_back
typedef vector<int> vi;

int n,m,cnt[maxn];
bool done[maxn],added[maxn],in[maxn];
vi RAL[maxn],AL[maxn],a,r,u,v,ans;

void expand(vi &v,int p){
	for(int i=0;i<n;++i){
		cnt[i]=AL[i].size();
		added[i]=false;
	}
	vi toadd;
	for(int x:v){
		toadd.pb(x);
		added[x]=true;
	}
	while(!toadd.empty()){
		int u=toadd.back();
		toadd.pop_back();
		for(int v:RAL[u]){
			--cnt[v];
			if(!added[v]&&(a[v]==p||cnt[v]==0)){
				toadd.pb(v);
				added[v]=true;
			}
		}
	}
	v.clear();
	for(int i=0;i<n;++i){
		if(added[i])v.pb(i);
	}
}

bool step(){
	int rem=0;
	vi charge;
	for(int i=0;i<n;++i){
		if(done[i])continue;
		AL[i].clear();
		RAL[i].clear();
		in[i]=false;
		++rem;
		if(r[i]==1)charge.pb(i);
	}
	if(rem==0)return false;
	for(int i=0;i<m;++i){
		if(!done[u[i]]&&!done[v[i]]){
			AL[u[i]].pb(v[i]);
			RAL[v[i]].pb(u[i]);
		}
	}
	expand(charge,1);
	
	if(charge.size()==rem){
		for(int x:charge)ans[x]=1;
		return false;
	}
	
	for(int x:charge)in[x]=true;
	vector<int> other;
	for(int i=0;i<n;++i){
		if(!done[i]&&!in[i])other.pb(i);
	}
	expand(other,0);
	for(int x:other)done[x]=true;
	return true;
}

vi who_wins(vi _a,vi _r,vi _u,vi _v){
	a=_a,r=_r,u=_u,v=_v;
	n=a.size(),m=u.size();
	ans.resize(n);
	while(step());
	return ans;
}

Compilation message

train.cpp: In function 'bool step()':
train.cpp:60:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |  if(charge.size()==rem){
      |     ~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1236 KB Output is correct
2 Correct 8 ms 1236 KB Output is correct
3 Correct 6 ms 1324 KB Output is correct
4 Correct 6 ms 1220 KB Output is correct
5 Correct 5 ms 1228 KB Output is correct
6 Correct 5 ms 1196 KB Output is correct
7 Correct 4 ms 1312 KB Output is correct
8 Correct 7 ms 1324 KB Output is correct
9 Correct 6 ms 1236 KB Output is correct
10 Correct 5 ms 1236 KB Output is correct
11 Correct 4 ms 1204 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 544 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 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 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 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 544 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 252 ms 1620 KB Output is correct
2 Correct 457 ms 1680 KB Output is correct
3 Correct 639 ms 1668 KB Output is correct
4 Correct 7 ms 1620 KB Output is correct
5 Correct 9 ms 1876 KB Output is correct
6 Correct 10 ms 1748 KB Output is correct
7 Correct 7 ms 1840 KB Output is correct
8 Correct 10 ms 1824 KB Output is correct
9 Correct 7 ms 1804 KB Output is correct
10 Correct 7 ms 1708 KB Output is correct
11 Correct 7 ms 1772 KB Output is correct
12 Correct 7 ms 1708 KB Output is correct
13 Correct 7 ms 1876 KB Output is correct
14 Correct 7 ms 1836 KB Output is correct
15 Correct 7 ms 1876 KB Output is correct
16 Correct 7 ms 1832 KB Output is correct
17 Correct 7 ms 1836 KB Output is correct
18 Correct 769 ms 1424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1364 KB Output is correct
2 Correct 8 ms 1584 KB Output is correct
3 Correct 7 ms 1748 KB Output is correct
4 Correct 10 ms 1800 KB Output is correct
5 Correct 8 ms 1824 KB Output is correct
6 Correct 8 ms 1748 KB Output is correct
7 Correct 7 ms 1748 KB Output is correct
8 Correct 6 ms 1748 KB Output is correct
9 Correct 7 ms 1748 KB Output is correct
10 Correct 7 ms 1876 KB Output is correct
11 Correct 7 ms 1832 KB Output is correct
12 Correct 7 ms 1876 KB Output is correct
13 Correct 11 ms 1836 KB Output is correct
14 Correct 8 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1620 KB Output is correct
2 Correct 7 ms 1876 KB Output is correct
3 Correct 8 ms 1744 KB Output is correct
4 Correct 6 ms 1620 KB Output is correct
5 Correct 1 ms 548 KB Output is correct
6 Correct 4 ms 1236 KB Output is correct
7 Correct 5 ms 1364 KB Output is correct
8 Correct 5 ms 1364 KB Output is correct
9 Correct 5 ms 1364 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 5 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1236 KB Output is correct
2 Correct 8 ms 1236 KB Output is correct
3 Correct 6 ms 1324 KB Output is correct
4 Correct 6 ms 1220 KB Output is correct
5 Correct 5 ms 1228 KB Output is correct
6 Correct 5 ms 1196 KB Output is correct
7 Correct 4 ms 1312 KB Output is correct
8 Correct 7 ms 1324 KB Output is correct
9 Correct 6 ms 1236 KB Output is correct
10 Correct 5 ms 1236 KB Output is correct
11 Correct 4 ms 1204 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 544 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 468 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
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 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 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 544 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 252 ms 1620 KB Output is correct
33 Correct 457 ms 1680 KB Output is correct
34 Correct 639 ms 1668 KB Output is correct
35 Correct 7 ms 1620 KB Output is correct
36 Correct 9 ms 1876 KB Output is correct
37 Correct 10 ms 1748 KB Output is correct
38 Correct 7 ms 1840 KB Output is correct
39 Correct 10 ms 1824 KB Output is correct
40 Correct 7 ms 1804 KB Output is correct
41 Correct 7 ms 1708 KB Output is correct
42 Correct 7 ms 1772 KB Output is correct
43 Correct 7 ms 1708 KB Output is correct
44 Correct 7 ms 1876 KB Output is correct
45 Correct 7 ms 1836 KB Output is correct
46 Correct 7 ms 1876 KB Output is correct
47 Correct 7 ms 1832 KB Output is correct
48 Correct 7 ms 1836 KB Output is correct
49 Correct 769 ms 1424 KB Output is correct
50 Correct 6 ms 1364 KB Output is correct
51 Correct 8 ms 1584 KB Output is correct
52 Correct 7 ms 1748 KB Output is correct
53 Correct 10 ms 1800 KB Output is correct
54 Correct 8 ms 1824 KB Output is correct
55 Correct 8 ms 1748 KB Output is correct
56 Correct 7 ms 1748 KB Output is correct
57 Correct 6 ms 1748 KB Output is correct
58 Correct 7 ms 1748 KB Output is correct
59 Correct 7 ms 1876 KB Output is correct
60 Correct 7 ms 1832 KB Output is correct
61 Correct 7 ms 1876 KB Output is correct
62 Correct 11 ms 1836 KB Output is correct
63 Correct 8 ms 1620 KB Output is correct
64 Correct 7 ms 1620 KB Output is correct
65 Correct 7 ms 1876 KB Output is correct
66 Correct 8 ms 1744 KB Output is correct
67 Correct 6 ms 1620 KB Output is correct
68 Correct 1 ms 548 KB Output is correct
69 Correct 4 ms 1236 KB Output is correct
70 Correct 5 ms 1364 KB Output is correct
71 Correct 5 ms 1364 KB Output is correct
72 Correct 5 ms 1364 KB Output is correct
73 Correct 2 ms 724 KB Output is correct
74 Correct 5 ms 1236 KB Output is correct
75 Correct 374 ms 1868 KB Output is correct
76 Correct 468 ms 1888 KB Output is correct
77 Correct 636 ms 1880 KB Output is correct
78 Correct 624 ms 1880 KB Output is correct
79 Correct 655 ms 1876 KB Output is correct
80 Correct 8 ms 1876 KB Output is correct
81 Correct 8 ms 1840 KB Output is correct
82 Correct 9 ms 1844 KB Output is correct
83 Correct 12 ms 1868 KB Output is correct
84 Correct 11 ms 1872 KB Output is correct
85 Correct 9 ms 1748 KB Output is correct
86 Correct 11 ms 1844 KB Output is correct
87 Correct 8 ms 1876 KB Output is correct
88 Correct 14 ms 1840 KB Output is correct
89 Correct 9 ms 1832 KB Output is correct
90 Correct 19 ms 1876 KB Output is correct
91 Correct 18 ms 1876 KB Output is correct
92 Correct 38 ms 1868 KB Output is correct
93 Correct 38 ms 1836 KB Output is correct
94 Correct 38 ms 1856 KB Output is correct
95 Correct 40 ms 1832 KB Output is correct
96 Correct 136 ms 1748 KB Output is correct
97 Correct 714 ms 1868 KB Output is correct
98 Correct 1027 ms 1840 KB Output is correct
99 Correct 1086 ms 1804 KB Output is correct
100 Correct 788 ms 1516 KB Output is correct