답안 #388201

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
388201 2021-04-10T13:37:19 Z Supersonic 기지국 (IOI20_stations) C++14
100 / 100
927 ms 968 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
int c[1001];set<int> a[1001];int l[1001];
int ch(int k,int p){
	int t=a[k].size()-1;for(auto i:a[k])if(i!=p)t+=ch(i,k);
	//if(k==0)for(auto i:a[k])cerr<<i<<'=';cout<<endl;
	if(k==0)t++;c[k]=t;return t;
}
void as(int k,int p,int v,int g){
	//cerr<<k<<' '<<p<<' '<<v<<' '<<g<<endl;
	int j=v;l[k]=v;
	for(auto i:a[k])if(i!=p){j+=(c[i]+1)*g;as(i,k,j,g*(-1));}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	for(int i=0;i<n-1;i++){
		a[u[i]].insert(v[i]);
		a[v[i]].insert(u[i]);
	}
	int r=ch(0,-1);as(0,-1,0,1);
	//for(int i=0;i<n;i++){cerr<<i<<'-'<<c[i]<<endl;}
	vector<int> f;for(int i=0;i<n;i++){f.push_back(l[i]);//cerr<<i<<':'<<l[i]<<endl;
	}
	memset(c,0,sizeof(c));memset(l,0,sizeof(l));for(int i=0;i<1001;i++)a[i].clear();
	return f;
}

int find_next_station(int s, int t, std::vector<int> c) {
	int n=c.size();
	//cerr<<s<<' '<<t<<endl;for(auto i:c)cerr<<i<<'-';cerr<<endl;
	if(s==0){
		for(int i=0;i<n;i++){if(t==c[i])return t;if(c[i]>t)return c[i];}
	}
	else if(s<c[0]){
		if(t<s)return c[n-1];
		for(int i=0;i<n-1;i++){if(t==c[i])return t;if(c[i]>t)return c[i];}
		return c[n-1];
	}
	else{
		if(t>s)return c[0];
		for(int i=n-1;i>=1;i--){if(t==c[i])return t;if(t>c[i])return c[i];}
		return c[0];
	}
	exit(1);
	return c[0];
}

Compilation message

stations.cpp: In function 'int ch(int, int)':
stations.cpp:8:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    8 |  if(k==0)t++;c[k]=t;return t;
      |  ^~
stations.cpp:8:14: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
    8 |  if(k==0)t++;c[k]=t;return t;
      |              ^
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:20:6: warning: unused variable 'r' [-Wunused-variable]
   20 |  int r=ch(0,-1);as(0,-1,0,1);
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 516 ms 968 KB Output is correct
2 Correct 443 ms 776 KB Output is correct
3 Correct 822 ms 708 KB Output is correct
4 Correct 628 ms 672 KB Output is correct
5 Correct 582 ms 832 KB Output is correct
6 Correct 464 ms 924 KB Output is correct
7 Correct 421 ms 804 KB Output is correct
8 Correct 3 ms 728 KB Output is correct
9 Correct 5 ms 728 KB Output is correct
10 Correct 1 ms 728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 426 ms 688 KB Output is correct
2 Correct 481 ms 784 KB Output is correct
3 Correct 771 ms 784 KB Output is correct
4 Correct 643 ms 656 KB Output is correct
5 Correct 604 ms 656 KB Output is correct
6 Correct 429 ms 668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 531 ms 784 KB Output is correct
2 Correct 455 ms 796 KB Output is correct
3 Correct 834 ms 680 KB Output is correct
4 Correct 628 ms 668 KB Output is correct
5 Correct 533 ms 656 KB Output is correct
6 Correct 424 ms 800 KB Output is correct
7 Correct 452 ms 784 KB Output is correct
8 Correct 3 ms 728 KB Output is correct
9 Correct 5 ms 724 KB Output is correct
10 Correct 2 ms 736 KB Output is correct
11 Correct 606 ms 672 KB Output is correct
12 Correct 428 ms 792 KB Output is correct
13 Correct 436 ms 792 KB Output is correct
14 Correct 418 ms 592 KB Output is correct
15 Correct 67 ms 676 KB Output is correct
16 Correct 66 ms 656 KB Output is correct
17 Correct 104 ms 808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 927 ms 656 KB Output is correct
2 Correct 650 ms 656 KB Output is correct
3 Correct 585 ms 656 KB Output is correct
4 Correct 3 ms 728 KB Output is correct
5 Correct 5 ms 728 KB Output is correct
6 Correct 2 ms 736 KB Output is correct
7 Correct 573 ms 668 KB Output is correct
8 Correct 910 ms 656 KB Output is correct
9 Correct 641 ms 656 KB Output is correct
10 Correct 543 ms 656 KB Output is correct
11 Correct 6 ms 728 KB Output is correct
12 Correct 6 ms 728 KB Output is correct
13 Correct 5 ms 736 KB Output is correct
14 Correct 3 ms 728 KB Output is correct
15 Correct 2 ms 728 KB Output is correct
16 Correct 444 ms 660 KB Output is correct
17 Correct 497 ms 656 KB Output is correct
18 Correct 485 ms 668 KB Output is correct
19 Correct 512 ms 708 KB Output is correct
20 Correct 532 ms 672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 521 ms 788 KB Output is correct
2 Correct 451 ms 804 KB Output is correct
3 Correct 856 ms 712 KB Output is correct
4 Correct 625 ms 912 KB Output is correct
5 Correct 552 ms 676 KB Output is correct
6 Correct 425 ms 968 KB Output is correct
7 Correct 423 ms 784 KB Output is correct
8 Correct 3 ms 728 KB Output is correct
9 Correct 4 ms 728 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 398 ms 916 KB Output is correct
12 Correct 520 ms 784 KB Output is correct
13 Correct 832 ms 672 KB Output is correct
14 Correct 627 ms 676 KB Output is correct
15 Correct 579 ms 656 KB Output is correct
16 Correct 435 ms 784 KB Output is correct
17 Correct 542 ms 656 KB Output is correct
18 Correct 448 ms 924 KB Output is correct
19 Correct 446 ms 800 KB Output is correct
20 Correct 466 ms 784 KB Output is correct
21 Correct 57 ms 676 KB Output is correct
22 Correct 66 ms 656 KB Output is correct
23 Correct 110 ms 804 KB Output is correct
24 Correct 6 ms 728 KB Output is correct
25 Correct 4 ms 740 KB Output is correct
26 Correct 5 ms 728 KB Output is correct
27 Correct 4 ms 728 KB Output is correct
28 Correct 2 ms 736 KB Output is correct
29 Correct 481 ms 672 KB Output is correct
30 Correct 505 ms 784 KB Output is correct
31 Correct 493 ms 656 KB Output is correct
32 Correct 492 ms 672 KB Output is correct
33 Correct 471 ms 656 KB Output is correct
34 Correct 323 ms 796 KB Output is correct
35 Correct 418 ms 784 KB Output is correct
36 Correct 415 ms 776 KB Output is correct
37 Correct 417 ms 784 KB Output is correct
38 Correct 446 ms 676 KB Output is correct
39 Correct 423 ms 940 KB Output is correct
40 Correct 423 ms 928 KB Output is correct
41 Correct 438 ms 796 KB Output is correct
42 Correct 64 ms 696 KB Output is correct
43 Correct 103 ms 924 KB Output is correct
44 Correct 123 ms 912 KB Output is correct
45 Correct 153 ms 784 KB Output is correct
46 Correct 337 ms 788 KB Output is correct
47 Correct 317 ms 784 KB Output is correct
48 Correct 57 ms 812 KB Output is correct
49 Correct 59 ms 836 KB Output is correct