Submission #307066

# Submission time Handle Problem Language Result Execution time Memory
307066 2020-09-26T22:36:28 Z junseo Stations (IOI20_stations) C++17
100 / 100
1117 ms 1312 KB
#include "stations.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define rmin(r, x) r = min(r, x)
#define rmax(r, x) r = max(r, x)
#define ends ' '
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int maxn = 1e3 + 10;

int T;
vector<int> l, adj[maxn];

void dfs(int u, int p, bool f) {
	if(f)	l[u] = T++;
	for(auto& v : adj[u]) if(v != p) dfs(v, u, f ^ true);
	if(!f)	l[u] = T++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	T = 0;
	l.resize(n);
	for(int i = 0; i < n; ++i)	adj[i].clear();
	for(int i = 0; i < u.size(); ++i) {
		adj[u[i]].eb(v[i]);
		adj[v[i]].eb(u[i]);
	}
	dfs(0, -1, true);
	return l;
}

int find_next_station(int s, int t, vector<int> c) {
	int n = c.size();
	if(n == 1)	return c[0];
	if(s < c[0]) {
		if(s && (t < s || c[n - 2] < t))	return c[n - 1];
		for(int i = 0; i < n; ++i)	if(t <= c[i])	return c[i];
	}
	else {
		if(t < c[1] || s < t)	return c[0];
		for(int i = n - 1; i >= 0; --i)	if(c[i] <= t)	return c[i];
	}
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for(int i = 0; i < u.size(); ++i) {
      |                 ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
   51 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 546 ms 1024 KB Output is correct
2 Correct 536 ms 1312 KB Output is correct
3 Correct 1071 ms 876 KB Output is correct
4 Correct 757 ms 768 KB Output is correct
5 Correct 659 ms 880 KB Output is correct
6 Correct 494 ms 1136 KB Output is correct
7 Correct 573 ms 772 KB Output is correct
8 Correct 3 ms 908 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 2 ms 1028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 448 ms 768 KB Output is correct
2 Correct 701 ms 820 KB Output is correct
3 Correct 923 ms 768 KB Output is correct
4 Correct 823 ms 888 KB Output is correct
5 Correct 733 ms 880 KB Output is correct
6 Correct 468 ms 832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 600 ms 1008 KB Output is correct
2 Correct 559 ms 1008 KB Output is correct
3 Correct 865 ms 1040 KB Output is correct
4 Correct 628 ms 768 KB Output is correct
5 Correct 632 ms 896 KB Output is correct
6 Correct 499 ms 1008 KB Output is correct
7 Correct 531 ms 1016 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 1 ms 880 KB Output is correct
11 Correct 712 ms 876 KB Output is correct
12 Correct 488 ms 964 KB Output is correct
13 Correct 544 ms 1056 KB Output is correct
14 Correct 488 ms 948 KB Output is correct
15 Correct 53 ms 1024 KB Output is correct
16 Correct 63 ms 836 KB Output is correct
17 Correct 130 ms 808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 970 ms 880 KB Output is correct
2 Correct 819 ms 768 KB Output is correct
3 Correct 765 ms 768 KB Output is correct
4 Correct 3 ms 1132 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 0 ms 876 KB Output is correct
7 Correct 746 ms 768 KB Output is correct
8 Correct 1101 ms 872 KB Output is correct
9 Correct 813 ms 1008 KB Output is correct
10 Correct 713 ms 876 KB Output is correct
11 Correct 5 ms 768 KB Output is correct
12 Correct 6 ms 768 KB Output is correct
13 Correct 6 ms 876 KB Output is correct
14 Correct 4 ms 768 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
16 Correct 552 ms 768 KB Output is correct
17 Correct 486 ms 896 KB Output is correct
18 Correct 637 ms 872 KB Output is correct
19 Correct 589 ms 876 KB Output is correct
20 Correct 517 ms 880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 613 ms 1024 KB Output is correct
2 Correct 510 ms 1024 KB Output is correct
3 Correct 932 ms 1032 KB Output is correct
4 Correct 856 ms 768 KB Output is correct
5 Correct 705 ms 876 KB Output is correct
6 Correct 438 ms 1024 KB Output is correct
7 Correct 559 ms 788 KB Output is correct
8 Correct 3 ms 1008 KB Output is correct
9 Correct 4 ms 876 KB Output is correct
10 Correct 1 ms 896 KB Output is correct
11 Correct 459 ms 936 KB Output is correct
12 Correct 661 ms 948 KB Output is correct
13 Correct 1117 ms 1040 KB Output is correct
14 Correct 742 ms 896 KB Output is correct
15 Correct 682 ms 1024 KB Output is correct
16 Correct 533 ms 820 KB Output is correct
17 Correct 642 ms 872 KB Output is correct
18 Correct 577 ms 1012 KB Output is correct
19 Correct 550 ms 1008 KB Output is correct
20 Correct 545 ms 820 KB Output is correct
21 Correct 76 ms 768 KB Output is correct
22 Correct 89 ms 768 KB Output is correct
23 Correct 132 ms 804 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 5 ms 768 KB Output is correct
26 Correct 6 ms 768 KB Output is correct
27 Correct 2 ms 768 KB Output is correct
28 Correct 2 ms 880 KB Output is correct
29 Correct 535 ms 768 KB Output is correct
30 Correct 611 ms 768 KB Output is correct
31 Correct 510 ms 1040 KB Output is correct
32 Correct 550 ms 876 KB Output is correct
33 Correct 606 ms 876 KB Output is correct
34 Correct 342 ms 1024 KB Output is correct
35 Correct 479 ms 1024 KB Output is correct
36 Correct 524 ms 1024 KB Output is correct
37 Correct 521 ms 892 KB Output is correct
38 Correct 532 ms 768 KB Output is correct
39 Correct 559 ms 1024 KB Output is correct
40 Correct 522 ms 768 KB Output is correct
41 Correct 521 ms 904 KB Output is correct
42 Correct 78 ms 824 KB Output is correct
43 Correct 138 ms 1176 KB Output is correct
44 Correct 132 ms 796 KB Output is correct
45 Correct 169 ms 920 KB Output is correct
46 Correct 329 ms 944 KB Output is correct
47 Correct 411 ms 780 KB Output is correct
48 Correct 66 ms 772 KB Output is correct
49 Correct 55 ms 1024 KB Output is correct