답안 #361984

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
361984 2021-02-01T13:58:18 Z ryansee 기지국 (IOI20_stations) C++14
100 / 100
1124 ms 1312 KB
#include "stations.h"
 
#include "bits/stdc++.h"
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusive
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }
 
using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 
 
long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (200006)
 
vector<int> label(int n, int k, vector<int> U, vector<int> V) {
	vector<vector<int>> v(n, vector<int>());
	FOR(i,0,n-2) v[U[i]].eb(V[i]), v[V[i]].eb(U[i]);
	vector<int> st(n, 0), en(n, 0);
	int co = 0;
	function<void(int,int)>dfs=[&](int x,int p){
		st[x]=co++;
		for(auto i:v[x]) if(i^p) dfs(i, x);
		en[x]=co++;
	};
	dfs(0, 0);
	vector<int> C(n);
	function<void(int,int,int)>dfs2=[&](int x,int p,int co){
		if(co == 0) C[x] = st[x];
		else C[x] = en[x];
		for(auto i:v[x]) if(i^p) dfs2(i, x, !co);
	};
	dfs2(0, 0, 0);
	vector<int> d;
	for(auto i:C) d.eb(i);
	sort(all(d));
	for(auto&i:C) i=lbd(d, i);
	return C;
}
int find_next_station(int S, int T, vector<int> c) {
	if(siz(c) == 1) return c[0];
	if(S == 0) {
		for(auto i:c) if(i >= T) return i;
		assert(0);
	}
	int pre, post, b;
	if(c[0] < S) { // S is post order
		post = S, pre = c[1] - 1, b = 1;
	} else { // S is pre
		pre = S, post = c[siz(c)-2] + 1, b = 0;
	}
	if(pre <= T && T <= post) { // in subtree
		if(b==0) {
			for(auto i:c) if(i >= T) return i;
			assert(0);
		} else {
			reverse(all(c));
			for(auto i:c) if(i <= T) return i;
			assert(0);
		}
	} else {
		if(b) return c[0];
		else return c.back();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 681 ms 1140 KB Output is correct
2 Correct 491 ms 1312 KB Output is correct
3 Correct 1035 ms 736 KB Output is correct
4 Correct 771 ms 912 KB Output is correct
5 Correct 776 ms 884 KB Output is correct
6 Correct 511 ms 876 KB Output is correct
7 Correct 465 ms 864 KB Output is correct
8 Correct 4 ms 1028 KB Output is correct
9 Correct 5 ms 736 KB Output is correct
10 Correct 2 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 564 ms 772 KB Output is correct
2 Correct 622 ms 768 KB Output is correct
3 Correct 922 ms 736 KB Output is correct
4 Correct 779 ms 756 KB Output is correct
5 Correct 624 ms 856 KB Output is correct
6 Correct 461 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 602 ms 864 KB Output is correct
2 Correct 542 ms 884 KB Output is correct
3 Correct 1124 ms 748 KB Output is correct
4 Correct 710 ms 756 KB Output is correct
5 Correct 623 ms 756 KB Output is correct
6 Correct 504 ms 884 KB Output is correct
7 Correct 617 ms 952 KB Output is correct
8 Correct 3 ms 756 KB Output is correct
9 Correct 5 ms 756 KB Output is correct
10 Correct 2 ms 756 KB Output is correct
11 Correct 586 ms 884 KB Output is correct
12 Correct 466 ms 924 KB Output is correct
13 Correct 544 ms 928 KB Output is correct
14 Correct 511 ms 776 KB Output is correct
15 Correct 71 ms 856 KB Output is correct
16 Correct 65 ms 756 KB Output is correct
17 Correct 119 ms 776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1051 ms 864 KB Output is correct
2 Correct 702 ms 756 KB Output is correct
3 Correct 748 ms 736 KB Output is correct
4 Correct 3 ms 756 KB Output is correct
5 Correct 5 ms 856 KB Output is correct
6 Correct 2 ms 736 KB Output is correct
7 Correct 659 ms 736 KB Output is correct
8 Correct 971 ms 756 KB Output is correct
9 Correct 714 ms 736 KB Output is correct
10 Correct 608 ms 864 KB Output is correct
11 Correct 7 ms 992 KB Output is correct
12 Correct 6 ms 736 KB Output is correct
13 Correct 6 ms 736 KB Output is correct
14 Correct 5 ms 864 KB Output is correct
15 Correct 2 ms 912 KB Output is correct
16 Correct 567 ms 736 KB Output is correct
17 Correct 633 ms 864 KB Output is correct
18 Correct 573 ms 864 KB Output is correct
19 Correct 659 ms 864 KB Output is correct
20 Correct 603 ms 1000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 701 ms 920 KB Output is correct
2 Correct 553 ms 936 KB Output is correct
3 Correct 984 ms 864 KB Output is correct
4 Correct 746 ms 1000 KB Output is correct
5 Correct 625 ms 992 KB Output is correct
6 Correct 556 ms 1052 KB Output is correct
7 Correct 432 ms 984 KB Output is correct
8 Correct 2 ms 912 KB Output is correct
9 Correct 4 ms 736 KB Output is correct
10 Correct 1 ms 756 KB Output is correct
11 Correct 592 ms 884 KB Output is correct
12 Correct 530 ms 904 KB Output is correct
13 Correct 935 ms 992 KB Output is correct
14 Correct 680 ms 864 KB Output is correct
15 Correct 693 ms 756 KB Output is correct
16 Correct 466 ms 776 KB Output is correct
17 Correct 651 ms 756 KB Output is correct
18 Correct 579 ms 1064 KB Output is correct
19 Correct 556 ms 924 KB Output is correct
20 Correct 484 ms 772 KB Output is correct
21 Correct 73 ms 856 KB Output is correct
22 Correct 67 ms 816 KB Output is correct
23 Correct 117 ms 716 KB Output is correct
24 Correct 6 ms 872 KB Output is correct
25 Correct 7 ms 756 KB Output is correct
26 Correct 5 ms 756 KB Output is correct
27 Correct 4 ms 864 KB Output is correct
28 Correct 2 ms 864 KB Output is correct
29 Correct 478 ms 736 KB Output is correct
30 Correct 534 ms 756 KB Output is correct
31 Correct 570 ms 1000 KB Output is correct
32 Correct 548 ms 992 KB Output is correct
33 Correct 557 ms 736 KB Output is correct
34 Correct 373 ms 884 KB Output is correct
35 Correct 543 ms 1044 KB Output is correct
36 Correct 536 ms 1064 KB Output is correct
37 Correct 549 ms 1236 KB Output is correct
38 Correct 519 ms 864 KB Output is correct
39 Correct 508 ms 992 KB Output is correct
40 Correct 496 ms 972 KB Output is correct
41 Correct 532 ms 1104 KB Output is correct
42 Correct 68 ms 736 KB Output is correct
43 Correct 137 ms 768 KB Output is correct
44 Correct 185 ms 736 KB Output is correct
45 Correct 176 ms 772 KB Output is correct
46 Correct 352 ms 808 KB Output is correct
47 Correct 310 ms 980 KB Output is correct
48 Correct 66 ms 1008 KB Output is correct
49 Correct 61 ms 864 KB Output is correct