Submission #623241

# Submission time Handle Problem Language Result Execution time Memory
623241 2022-08-05T11:08:31 Z AriaH Stations (IOI20_stations) C++17
100 / 100
984 ms 864 KB
#include "stations.h"
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

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

#define endl "\n"
#define F first
#define S second
#define Mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define fast_io ios::sync_with_stdio(0);cin.tie(0);cout.tie()

const int N = 1e3 + 10;
const int LOG = 20;
const ll mod = 1e9 + 7;
const ll inf = 8e18;

int ptr = -1, H[N], St[N], Fi[N];

vector < int > G[N];

void dfs(int v, int P = -1)
{
	St[v] = ++ ptr;
	for(auto u : G[v])
	{
		if(u == P) continue;
		H[u] = H[v] + 1;
		dfs(u, v);
	}
	Fi[v] = ++ ptr;
}

vector < int > label(int n, int k, vector < int > A, vector < int > B)
{
	ptr = -1;
	for(int i = 0; i < n; i ++)
	{
		H[i] = 0;
		G[i].clear();
		St[i] = Fi[i] = 0;
	}
	vector < int > ret(n);
	for(int i = 0; i < n - 1; i ++)
	{
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}
	dfs(0, -1);
	vector < int > cm;
	for(int i = 0; i < n; i ++)
	{
		if(H[i] & 1)
		{
			ret[i] = Fi[i];
		}
		else
		{
			ret[i] = St[i];
		}
		cm.push_back(ret[i]);
	}
	sort(all(cm));
	for(int i = 0; i < n; i ++)
	{
		ret[i] = lower_bound(all(cm), ret[i]) - cm.begin();
	}
	return ret;
}

int find_next_station(int s, int t, vector < int > c)
{
	int sz = SZ(c);
	sort(all(c));
	int tp = 1;
	for(auto u : c)
	{
		if(u > s) tp = 0;
	}
	if(s == 0)
	{
		int id = lower_bound(all(c), t) - c.begin();
		return c[id];
	}
	if(tp == 0)
	{
		if(t < s) return c.back();
		int id = lower_bound(all(c), t) - c.begin();
		if(id <= sz - 2)
		{
			return c[id];
		}
		return c.back();
	}
	if(t > s) return c[0];
	if(t <= c[0]) return c[0];
	int id = upper_bound(all(c), t) - c.begin() - 1;
	return c[id];
}
# Verdict Execution time Memory Grader output
1 Correct 514 ms 548 KB Output is correct
2 Correct 457 ms 544 KB Output is correct
3 Correct 934 ms 532 KB Output is correct
4 Correct 635 ms 528 KB Output is correct
5 Correct 490 ms 528 KB Output is correct
6 Correct 475 ms 528 KB Output is correct
7 Correct 444 ms 528 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 4 ms 500 KB Output is correct
10 Correct 0 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 448 ms 544 KB Output is correct
2 Correct 469 ms 528 KB Output is correct
3 Correct 898 ms 528 KB Output is correct
4 Correct 663 ms 420 KB Output is correct
5 Correct 605 ms 548 KB Output is correct
6 Correct 445 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 556 ms 540 KB Output is correct
2 Correct 449 ms 540 KB Output is correct
3 Correct 782 ms 524 KB Output is correct
4 Correct 692 ms 572 KB Output is correct
5 Correct 633 ms 520 KB Output is correct
6 Correct 420 ms 548 KB Output is correct
7 Correct 449 ms 532 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 3 ms 628 KB Output is correct
10 Correct 0 ms 632 KB Output is correct
11 Correct 579 ms 544 KB Output is correct
12 Correct 435 ms 656 KB Output is correct
13 Correct 415 ms 864 KB Output is correct
14 Correct 435 ms 544 KB Output is correct
15 Correct 57 ms 548 KB Output is correct
16 Correct 59 ms 548 KB Output is correct
17 Correct 100 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 984 ms 524 KB Output is correct
2 Correct 679 ms 532 KB Output is correct
3 Correct 582 ms 544 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 2 ms 628 KB Output is correct
6 Correct 0 ms 620 KB Output is correct
7 Correct 591 ms 524 KB Output is correct
8 Correct 893 ms 528 KB Output is correct
9 Correct 579 ms 544 KB Output is correct
10 Correct 520 ms 544 KB Output is correct
11 Correct 5 ms 500 KB Output is correct
12 Correct 5 ms 620 KB Output is correct
13 Correct 4 ms 492 KB Output is correct
14 Correct 2 ms 500 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 479 ms 528 KB Output is correct
17 Correct 432 ms 528 KB Output is correct
18 Correct 434 ms 548 KB Output is correct
19 Correct 417 ms 544 KB Output is correct
20 Correct 448 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 520 ms 544 KB Output is correct
2 Correct 409 ms 532 KB Output is correct
3 Correct 792 ms 528 KB Output is correct
4 Correct 648 ms 524 KB Output is correct
5 Correct 595 ms 532 KB Output is correct
6 Correct 427 ms 536 KB Output is correct
7 Correct 451 ms 548 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 4 ms 620 KB Output is correct
10 Correct 0 ms 620 KB Output is correct
11 Correct 364 ms 544 KB Output is correct
12 Correct 532 ms 548 KB Output is correct
13 Correct 847 ms 420 KB Output is correct
14 Correct 662 ms 416 KB Output is correct
15 Correct 544 ms 544 KB Output is correct
16 Correct 436 ms 548 KB Output is correct
17 Correct 529 ms 544 KB Output is correct
18 Correct 362 ms 660 KB Output is correct
19 Correct 470 ms 584 KB Output is correct
20 Correct 396 ms 544 KB Output is correct
21 Correct 45 ms 632 KB Output is correct
22 Correct 66 ms 544 KB Output is correct
23 Correct 117 ms 672 KB Output is correct
24 Correct 4 ms 500 KB Output is correct
25 Correct 4 ms 620 KB Output is correct
26 Correct 3 ms 628 KB Output is correct
27 Correct 2 ms 628 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 498 ms 528 KB Output is correct
30 Correct 483 ms 528 KB Output is correct
31 Correct 463 ms 544 KB Output is correct
32 Correct 440 ms 528 KB Output is correct
33 Correct 364 ms 528 KB Output is correct
34 Correct 316 ms 548 KB Output is correct
35 Correct 434 ms 656 KB Output is correct
36 Correct 447 ms 640 KB Output is correct
37 Correct 461 ms 640 KB Output is correct
38 Correct 427 ms 652 KB Output is correct
39 Correct 393 ms 764 KB Output is correct
40 Correct 448 ms 676 KB Output is correct
41 Correct 355 ms 724 KB Output is correct
42 Correct 54 ms 572 KB Output is correct
43 Correct 113 ms 544 KB Output is correct
44 Correct 109 ms 548 KB Output is correct
45 Correct 159 ms 548 KB Output is correct
46 Correct 284 ms 528 KB Output is correct
47 Correct 284 ms 536 KB Output is correct
48 Correct 47 ms 676 KB Output is correct
49 Correct 47 ms 700 KB Output is correct