답안 #430497

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430497 2021-06-16T14:42:13 Z alishahali1382 기지국 (IOI20_stations) C++14
100 / 100
1555 ms 804 KB
#include "stations.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define debug(x) {cerr<<#x<<"="<<x<<"\n";}
#define debug2(x, y) {cerr<<"{"<<#x<<", "<<#y<<"}={"<<x<<", "<<y<<"}\n";}
#define debugp(p) {cerr<<#p<<"={"<<p.first<<", "<<p.second<<"}\n";}
#define debugv(abcd) {cerr<<#abcd<<": "; for (auto dcba:abcd) cerr<<dcba<<", ";cerr<<"\n";}
#define pb push_back
#define all(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())

const int inf=1000000100; // 1e9
const ll INF=10000000001000000; // 1e16
const int mod=1000000007;
const int MAXN=1010;

int n, m, k, x, y, a, b, t, ans;
int stt[MAXN], fnt[MAXN], h[MAXN], timer;
vi G[MAXN];

void dfs(int node, int par){
	stt[node]=timer++;
	for (int v:G[node]) if (v!=par){
		h[v]=h[node]+1;
		dfs(v, node);
	}
	fnt[node]=timer++;
}

vi label(int _n, int _k, vi U, vi V){
	n=_n;
	k=_k;
	vi out(n);
	for (int i=0; i<n; i++) G[i].clear();
	for (int i=0; i<n-1; i++){
		int u=U[i], v=V[i];
		G[u].pb(v);
		G[v].pb(u);
	}
	timer=0;
	dfs(0, 0);
	for (int i=0; i<n; i++){
		if (h[i]&1) out[i]=fnt[i];
		else out[i]=stt[i];
	}
	vi comp=out;
	sort(all(comp));
	for (int i=0; i<n; i++) out[i]=lower_bound(all(comp), out[i])-comp.begin();
	return out;
}

int find_next_station(int s, int t, vi adj){
	// cerr<<"\n";
	// debug2(s, t)
	for (int x:adj) if (x==t) return x;
	if (SZ(adj)==1) return adj[0];
	sort(all(adj));
	if (s<adj[0]){
		// stt
		int par=-1;
		if (s){
			par=adj.back();
			adj.pop_back();
		}
		int stt_s=s, fnt_s=adj.back();
		if (t<stt_s || fnt_s<t) return par;
		return *lower_bound(all(adj), t);
	}
	// fnt
	assert(adj.back()<s);
	int par=adj[0];
	reverse(all(adj));
	adj.pop_back();
	
	int stt_s=adj.back(), fnt_s=s;
	if (t<stt_s || fnt_s<t) return par;
	while (SZ(adj)>1){
		int v=adj.back();
		adj.pop_back();
		if (adj.back()<t) continue ;
		return v;
	}
	return adj.back();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 848 ms 628 KB Output is correct
2 Correct 505 ms 636 KB Output is correct
3 Correct 1192 ms 500 KB Output is correct
4 Correct 989 ms 508 KB Output is correct
5 Correct 1085 ms 584 KB Output is correct
6 Correct 726 ms 668 KB Output is correct
7 Correct 520 ms 512 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 6 ms 596 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 529 ms 500 KB Output is correct
2 Correct 714 ms 500 KB Output is correct
3 Correct 979 ms 504 KB Output is correct
4 Correct 1117 ms 468 KB Output is correct
5 Correct 664 ms 400 KB Output is correct
6 Correct 755 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 752 ms 532 KB Output is correct
2 Correct 682 ms 636 KB Output is correct
3 Correct 1555 ms 528 KB Output is correct
4 Correct 949 ms 644 KB Output is correct
5 Correct 822 ms 564 KB Output is correct
6 Correct 623 ms 636 KB Output is correct
7 Correct 674 ms 640 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 982 ms 512 KB Output is correct
12 Correct 1087 ms 764 KB Output is correct
13 Correct 540 ms 684 KB Output is correct
14 Correct 536 ms 528 KB Output is correct
15 Correct 52 ms 584 KB Output is correct
16 Correct 76 ms 716 KB Output is correct
17 Correct 157 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1498 ms 768 KB Output is correct
2 Correct 706 ms 508 KB Output is correct
3 Correct 776 ms 400 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 4 ms 576 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 702 ms 592 KB Output is correct
8 Correct 1549 ms 648 KB Output is correct
9 Correct 1059 ms 576 KB Output is correct
10 Correct 1012 ms 516 KB Output is correct
11 Correct 9 ms 596 KB Output is correct
12 Correct 5 ms 596 KB Output is correct
13 Correct 7 ms 608 KB Output is correct
14 Correct 5 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 477 ms 512 KB Output is correct
17 Correct 576 ms 500 KB Output is correct
18 Correct 530 ms 528 KB Output is correct
19 Correct 536 ms 528 KB Output is correct
20 Correct 791 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 494 ms 584 KB Output is correct
2 Correct 699 ms 624 KB Output is correct
3 Correct 1232 ms 564 KB Output is correct
4 Correct 1013 ms 528 KB Output is correct
5 Correct 899 ms 528 KB Output is correct
6 Correct 748 ms 528 KB Output is correct
7 Correct 782 ms 528 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 3 ms 544 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 677 ms 512 KB Output is correct
12 Correct 505 ms 508 KB Output is correct
13 Correct 1214 ms 532 KB Output is correct
14 Correct 972 ms 508 KB Output is correct
15 Correct 901 ms 732 KB Output is correct
16 Correct 523 ms 512 KB Output is correct
17 Correct 909 ms 508 KB Output is correct
18 Correct 697 ms 632 KB Output is correct
19 Correct 740 ms 640 KB Output is correct
20 Correct 483 ms 512 KB Output is correct
21 Correct 84 ms 528 KB Output is correct
22 Correct 110 ms 548 KB Output is correct
23 Correct 108 ms 528 KB Output is correct
24 Correct 5 ms 480 KB Output is correct
25 Correct 5 ms 596 KB Output is correct
26 Correct 8 ms 596 KB Output is correct
27 Correct 5 ms 600 KB Output is correct
28 Correct 4 ms 544 KB Output is correct
29 Correct 799 ms 528 KB Output is correct
30 Correct 435 ms 528 KB Output is correct
31 Correct 668 ms 516 KB Output is correct
32 Correct 597 ms 508 KB Output is correct
33 Correct 585 ms 400 KB Output is correct
34 Correct 502 ms 512 KB Output is correct
35 Correct 548 ms 636 KB Output is correct
36 Correct 553 ms 740 KB Output is correct
37 Correct 562 ms 696 KB Output is correct
38 Correct 552 ms 752 KB Output is correct
39 Correct 410 ms 756 KB Output is correct
40 Correct 604 ms 684 KB Output is correct
41 Correct 517 ms 624 KB Output is correct
42 Correct 55 ms 548 KB Output is correct
43 Correct 118 ms 804 KB Output is correct
44 Correct 205 ms 600 KB Output is correct
45 Correct 162 ms 616 KB Output is correct
46 Correct 355 ms 664 KB Output is correct
47 Correct 404 ms 656 KB Output is correct
48 Correct 74 ms 656 KB Output is correct
49 Correct 83 ms 656 KB Output is correct