Submission #304977

# Submission time Handle Problem Language Result Execution time Memory
304977 2020-09-22T10:16:36 Z arnold518 Stations (IOI20_stations) C++14
100 / 100
1176 ms 1128 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

static const int MAXN = 1000;

static int N, K;
static vector<int> adj[MAXN+10];
static int L[MAXN+10], R[MAXN+10], D[MAXN+10];
static int ans[MAXN+10];

static int cnt;

void dfs(int now, int bef, int col)
{
	if(col) cnt++;
	L[now]=cnt;
	D[now]=col;
	for(int nxt : adj[now])
	{
		if(nxt==bef) continue;
		dfs(nxt, now, 1-col);
	}
	if(!col) cnt++;
	R[now]=cnt;
}

vector<int> label(int _N, int _K, vector<int> _U, vector<int> _V)
{
	N=_N;
	for(int i=0; i+1<N; i++)
	{
		int u=_U[i], v=_V[i];
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	cnt=0;
	dfs(0, 0, 1);

	for(int i=0; i<N; i++)
	{
		if(D[i]) ans[i]=L[i];
		else ans[i]=R[i];
	}

	for(int i=0; i<N; i++) adj[i].clear();

	vector<int> ans2;
	ans2.resize(N);
	for(int i=0; i<N; i++) ans2[i]=ans[i];
	return ans2;
}


int find_next_station(int _S, int _T, vector<int> _C)
{
static int S, T, D;
static vector<int> C;
	S=_S; T=_T; D=_C.size(); C=_C;

	if(D==1) return C[0];
	if(S==0) return *lower_bound(C.begin(), C.end(), T);

	if(C[0]>S)
	{
		int P=C.back(); C.pop_back();
		if(S+1<=T && T<=C.back()) return *lower_bound(C.begin(), C.end(), T);
		else return P;
	}
	else
	{
		int P=C[0]; C.erase(C.begin());
		if(C[0]<=T && T<=S-1) return *(--upper_bound(C.begin(), C.end(), T));
		else return P;
	}
}

Compilation message

stations.cpp:11:15: warning: 'K' defined but not used [-Wunused-variable]
   11 | static int N, K;
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 638 ms 1128 KB Output is correct
2 Correct 556 ms 1056 KB Output is correct
3 Correct 1003 ms 768 KB Output is correct
4 Correct 752 ms 916 KB Output is correct
5 Correct 665 ms 896 KB Output is correct
6 Correct 458 ms 1024 KB Output is correct
7 Correct 581 ms 772 KB Output is correct
8 Correct 4 ms 968 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 3 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 604 ms 768 KB Output is correct
2 Correct 623 ms 780 KB Output is correct
3 Correct 944 ms 908 KB Output is correct
4 Correct 825 ms 776 KB Output is correct
5 Correct 604 ms 1024 KB Output is correct
6 Correct 514 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 865 ms 1044 KB Output is correct
2 Correct 523 ms 1008 KB Output is correct
3 Correct 1134 ms 776 KB Output is correct
4 Correct 757 ms 768 KB Output is correct
5 Correct 756 ms 768 KB Output is correct
6 Correct 561 ms 1024 KB Output is correct
7 Correct 633 ms 896 KB Output is correct
8 Correct 4 ms 896 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 2 ms 832 KB Output is correct
11 Correct 598 ms 1008 KB Output is correct
12 Correct 593 ms 1008 KB Output is correct
13 Correct 627 ms 1040 KB Output is correct
14 Correct 505 ms 768 KB Output is correct
15 Correct 61 ms 768 KB Output is correct
16 Correct 68 ms 808 KB Output is correct
17 Correct 146 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 985 ms 768 KB Output is correct
2 Correct 813 ms 768 KB Output is correct
3 Correct 679 ms 784 KB Output is correct
4 Correct 3 ms 896 KB Output is correct
5 Correct 7 ms 768 KB Output is correct
6 Correct 2 ms 896 KB Output is correct
7 Correct 892 ms 768 KB Output is correct
8 Correct 1063 ms 768 KB Output is correct
9 Correct 849 ms 768 KB Output is correct
10 Correct 675 ms 904 KB Output is correct
11 Correct 8 ms 896 KB Output is correct
12 Correct 8 ms 768 KB Output is correct
13 Correct 6 ms 768 KB Output is correct
14 Correct 4 ms 768 KB Output is correct
15 Correct 2 ms 768 KB Output is correct
16 Correct 592 ms 1024 KB Output is correct
17 Correct 635 ms 864 KB Output is correct
18 Correct 548 ms 916 KB Output is correct
19 Correct 683 ms 1008 KB Output is correct
20 Correct 704 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 597 ms 1008 KB Output is correct
2 Correct 549 ms 1024 KB Output is correct
3 Correct 1176 ms 776 KB Output is correct
4 Correct 757 ms 776 KB Output is correct
5 Correct 663 ms 896 KB Output is correct
6 Correct 628 ms 1044 KB Output is correct
7 Correct 450 ms 784 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 2 ms 896 KB Output is correct
11 Correct 533 ms 896 KB Output is correct
12 Correct 580 ms 768 KB Output is correct
13 Correct 1015 ms 896 KB Output is correct
14 Correct 826 ms 776 KB Output is correct
15 Correct 772 ms 776 KB Output is correct
16 Correct 485 ms 896 KB Output is correct
17 Correct 593 ms 904 KB Output is correct
18 Correct 565 ms 1024 KB Output is correct
19 Correct 634 ms 1024 KB Output is correct
20 Correct 576 ms 904 KB Output is correct
21 Correct 76 ms 768 KB Output is correct
22 Correct 71 ms 768 KB Output is correct
23 Correct 112 ms 896 KB Output is correct
24 Correct 5 ms 776 KB Output is correct
25 Correct 6 ms 928 KB Output is correct
26 Correct 6 ms 776 KB Output is correct
27 Correct 4 ms 896 KB Output is correct
28 Correct 2 ms 768 KB Output is correct
29 Correct 580 ms 768 KB Output is correct
30 Correct 622 ms 816 KB Output is correct
31 Correct 705 ms 800 KB Output is correct
32 Correct 562 ms 768 KB Output is correct
33 Correct 631 ms 1024 KB Output is correct
34 Correct 344 ms 1024 KB Output is correct
35 Correct 440 ms 1024 KB Output is correct
36 Correct 578 ms 1024 KB Output is correct
37 Correct 577 ms 820 KB Output is correct
38 Correct 645 ms 896 KB Output is correct
39 Correct 608 ms 1024 KB Output is correct
40 Correct 600 ms 1024 KB Output is correct
41 Correct 616 ms 1024 KB Output is correct
42 Correct 72 ms 896 KB Output is correct
43 Correct 132 ms 880 KB Output is correct
44 Correct 152 ms 908 KB Output is correct
45 Correct 166 ms 992 KB Output is correct
46 Correct 345 ms 776 KB Output is correct
47 Correct 365 ms 768 KB Output is correct
48 Correct 59 ms 1024 KB Output is correct
49 Correct 75 ms 1024 KB Output is correct