Submission #833916

# Submission time Handle Problem Language Result Execution time Memory
833916 2023-08-22T09:29:09 Z penguinman Stations (IOI20_stations) C++17
100 / 100
798 ms 804 KB
#include "stations.h"
#include <bits/stdc++.h>

#ifndef EVAL
#include "stub.cpp"
#endif

using ll = int;
using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;

#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define ln "\n"
#define pb emplace_back
#define mp std::make_pair
#define mtp std::make_tuple
#define all(a) a.begin(),a.end()

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	if(k == 1000){
		vi num(n);
		rep(i,0,n) num[i] = i;
	}
	constexpr int max = 1000;
	int ord = 0;
	vi left(n, -1), right(n, -1);
	vii edge(n);
	rep(i,0,n-1){
		edge[u[i]].pb(v[i]);
		edge[v[i]].pb(u[i]);
	}
	vector<bool> flag(n);
	std::function<void(int)> dfs = [&](int now){
		if(flag[now]) left[now] = ord++;
		else left[now] = -2;
		for(auto next: edge[now]){
			if(left[next] == -1){
				flag[next] = !flag[now];
				dfs(next);
			}
		}
		if(!flag[now]) right[now] = ord++;
	};
	dfs(0);
	vi num(n);
	rep(i,0,n){
		if(flag[i]) num[i] = left[i];
		else num[i] = right[i];
	}
	num[0] = max;
	return num;
}

int find_next_station(int s, int t, std::vector<int> c) {
	constexpr int max = 1000;
	sort(all(c));
	int ls, rs;
	// left
	if(c[0] > s){
		ls = s;
		reverse(all(c));
		if(c.size() == 1) rs = ls;
		else rs = c[1];

		if(ls <= t && t <= rs){
			int start = 1;
			c.pb(ls-1);
			rep(i,start,c.size()-1){
				int el = c[i];
				int lc = c[i+1]+1, rc = el;
				if(lc <= t && t <= rc) return el;
			}
		}
		else{
			return c[0];
		}
	}
	// right
	else if(c.back() < s){
		rs = s;
		if(s == max){
			rs = max;
			ls = 0;
		}
		else{
			if(c.size() == 1) ls = rs;
			else ls = c[1];
		}

		if(ls <= t && t <= rs){
			int start = 1;
			if(s == max) start = 0;
			c.pb(rs+1);
			rep(i,start,c.size()-1){
				int el = c[i];
				int lc = el, rc = c[i+1]-1;
				if(lc <= t && t <= rc) return el;
			}
		}
		else{
			return c[0];
		}
	}
	else assert(false);
	
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:114:1: warning: control reaches end of non-void function [-Wreturn-type]
  114 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 493 ms 544 KB Output is correct
2 Correct 316 ms 544 KB Output is correct
3 Correct 588 ms 524 KB Output is correct
4 Correct 436 ms 416 KB Output is correct
5 Correct 530 ms 420 KB Output is correct
6 Correct 309 ms 548 KB Output is correct
7 Correct 317 ms 544 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 387 ms 672 KB Output is correct
2 Correct 392 ms 544 KB Output is correct
3 Correct 559 ms 416 KB Output is correct
4 Correct 440 ms 420 KB Output is correct
5 Correct 414 ms 416 KB Output is correct
6 Correct 372 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 395 ms 544 KB Output is correct
2 Correct 310 ms 548 KB Output is correct
3 Correct 591 ms 508 KB Output is correct
4 Correct 426 ms 500 KB Output is correct
5 Correct 486 ms 504 KB Output is correct
6 Correct 472 ms 568 KB Output is correct
7 Correct 391 ms 548 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 4 ms 500 KB Output is correct
10 Correct 2 ms 500 KB Output is correct
11 Correct 532 ms 512 KB Output is correct
12 Correct 314 ms 620 KB Output is correct
13 Correct 343 ms 804 KB Output is correct
14 Correct 365 ms 548 KB Output is correct
15 Correct 38 ms 488 KB Output is correct
16 Correct 46 ms 624 KB Output is correct
17 Correct 81 ms 572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 798 ms 420 KB Output is correct
2 Correct 630 ms 420 KB Output is correct
3 Correct 374 ms 416 KB Output is correct
4 Correct 3 ms 500 KB Output is correct
5 Correct 3 ms 500 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 504 ms 548 KB Output is correct
8 Correct 508 ms 416 KB Output is correct
9 Correct 454 ms 416 KB Output is correct
10 Correct 524 ms 416 KB Output is correct
11 Correct 5 ms 500 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 500 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 342 ms 420 KB Output is correct
17 Correct 373 ms 420 KB Output is correct
18 Correct 388 ms 416 KB Output is correct
19 Correct 413 ms 492 KB Output is correct
20 Correct 437 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 452 ms 544 KB Output is correct
2 Correct 415 ms 544 KB Output is correct
3 Correct 743 ms 420 KB Output is correct
4 Correct 439 ms 416 KB Output is correct
5 Correct 464 ms 420 KB Output is correct
6 Correct 394 ms 572 KB Output is correct
7 Correct 453 ms 680 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 0 ms 500 KB Output is correct
11 Correct 355 ms 544 KB Output is correct
12 Correct 474 ms 548 KB Output is correct
13 Correct 606 ms 420 KB Output is correct
14 Correct 485 ms 420 KB Output is correct
15 Correct 454 ms 416 KB Output is correct
16 Correct 257 ms 548 KB Output is correct
17 Correct 466 ms 420 KB Output is correct
18 Correct 399 ms 628 KB Output is correct
19 Correct 408 ms 664 KB Output is correct
20 Correct 337 ms 500 KB Output is correct
21 Correct 44 ms 444 KB Output is correct
22 Correct 55 ms 564 KB Output is correct
23 Correct 95 ms 668 KB Output is correct
24 Correct 3 ms 500 KB Output is correct
25 Correct 5 ms 488 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 321 ms 416 KB Output is correct
30 Correct 402 ms 504 KB Output is correct
31 Correct 511 ms 420 KB Output is correct
32 Correct 534 ms 420 KB Output is correct
33 Correct 410 ms 416 KB Output is correct
34 Correct 294 ms 544 KB Output is correct
35 Correct 262 ms 772 KB Output is correct
36 Correct 351 ms 624 KB Output is correct
37 Correct 270 ms 632 KB Output is correct
38 Correct 311 ms 636 KB Output is correct
39 Correct 420 ms 632 KB Output is correct
40 Correct 387 ms 700 KB Output is correct
41 Correct 375 ms 708 KB Output is correct
42 Correct 55 ms 572 KB Output is correct
43 Correct 101 ms 548 KB Output is correct
44 Correct 114 ms 548 KB Output is correct
45 Correct 138 ms 548 KB Output is correct
46 Correct 280 ms 544 KB Output is correct
47 Correct 181 ms 544 KB Output is correct
48 Correct 46 ms 684 KB Output is correct
49 Correct 54 ms 728 KB Output is correct