Submission #683638

# Submission time Handle Problem Language Result Execution time Memory
683638 2023-01-19T03:32:47 Z whqkrtk04 Stations (IOI20_stations) C++17
100 / 100
936 ms 776 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
#define fi first
#define se second
const int INF = 1e9+1;
const int P = 1000000007;
const ll LLINF = (ll)1e18+1;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) { os << p.fi << " " << p.se; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { for(auto i : v) os << i << " "; os << "\n"; return os; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_int_distribution<int>(x, y)(rng)

const int MAX = 1000;

void dfs(int x, int d, int &cnt, vector<vector<int>> &E, vector<int> &I, vector<int> &O, vector<int> &D, vector<bool> &vis) {
	if(vis[x]) return;
	vis[x] = true; I[x] = cnt++; D[x] = d;
	for(auto i : E[x]) dfs(i, d+1, cnt, E, I, O, D, vis);
	O[x] = cnt++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	int cnt = 0;
	vector<bool> vis(n, false);
	vector<int> I(n), O(n), D(n);
	vector<vector<int>> E(n);
	for(int i = 0; i+1 < n; i++) {
		E[u[i]].push_back(v[i]);
		E[v[i]].push_back(u[i]);
	}
	dfs(0, 0, cnt, E, I, O, D, vis);
	vector<int> ret(n);
	for(int i = 0; i < n; i++) {
		if(D[i]%2 == 0) ret[i] = O[i];
		else ret[i] = I[i];
	}
	vector<int> T(ret);
	sort(T.begin(), T.end());
	for(auto &i : ret) i = lower_bound(T.begin(), T.end(), i) - T.begin();
	//cout << ret;
	return ret;
}

int find_next_station(int s, int t, vector<int> c) {
	int ret;
	vector<int> T;
	if(c.front() > s) {
		T.push_back(s);
		for(int i = 0; i+1 < c.size(); i++) T.push_back(c[i]);
		ret = c.back();
		if(T.front() >= t || T.back() < t) return ret;
		for(int i = 0; i+1 < T.size(); i++)
			if(t > T[i] && T[i+1] >= t) return T[i+1];
	} else {
		ret = c.front();
		for(int i = 1; i < c.size(); i++) T.push_back(c[i]);
		T.push_back(s);
		if(T.front() > t || T.back() <= t) return ret;
		for(int i = 0; i+1 < T.size(); i++)
			if(t >= T[i] && T[i+1] > t) return T[i];
	}
	return ret;
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:57:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for(int i = 0; i+1 < c.size(); i++) T.push_back(c[i]);
      |                  ~~~~^~~~~~~~~~
stations.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for(int i = 0; i+1 < T.size(); i++)
      |                  ~~~~^~~~~~~~~~
stations.cpp:64:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   for(int i = 1; i < c.size(); i++) T.push_back(c[i]);
      |                  ~~^~~~~~~~~~
stations.cpp:67:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for(int i = 0; i+1 < T.size(); i++)
      |                  ~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 577 ms 636 KB Output is correct
2 Correct 475 ms 628 KB Output is correct
3 Correct 902 ms 416 KB Output is correct
4 Correct 664 ms 508 KB Output is correct
5 Correct 537 ms 492 KB Output is correct
6 Correct 464 ms 676 KB Output is correct
7 Correct 469 ms 636 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 4 ms 500 KB Output is correct
10 Correct 0 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 452 ms 504 KB Output is correct
2 Correct 533 ms 504 KB Output is correct
3 Correct 936 ms 420 KB Output is correct
4 Correct 650 ms 516 KB Output is correct
5 Correct 635 ms 512 KB Output is correct
6 Correct 416 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 516 ms 672 KB Output is correct
2 Correct 443 ms 676 KB Output is correct
3 Correct 916 ms 504 KB Output is correct
4 Correct 696 ms 420 KB Output is correct
5 Correct 624 ms 508 KB Output is correct
6 Correct 471 ms 624 KB Output is correct
7 Correct 491 ms 672 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 548 ms 508 KB Output is correct
12 Correct 415 ms 724 KB Output is correct
13 Correct 480 ms 680 KB Output is correct
14 Correct 507 ms 504 KB Output is correct
15 Correct 35 ms 448 KB Output is correct
16 Correct 54 ms 532 KB Output is correct
17 Correct 84 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 869 ms 420 KB Output is correct
2 Correct 694 ms 508 KB Output is correct
3 Correct 485 ms 420 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 5 ms 492 KB Output is correct
6 Correct 0 ms 500 KB Output is correct
7 Correct 516 ms 512 KB Output is correct
8 Correct 724 ms 420 KB Output is correct
9 Correct 620 ms 416 KB Output is correct
10 Correct 538 ms 512 KB Output is correct
11 Correct 5 ms 492 KB Output is correct
12 Correct 6 ms 492 KB Output is correct
13 Correct 4 ms 492 KB Output is correct
14 Correct 3 ms 492 KB Output is correct
15 Correct 1 ms 500 KB Output is correct
16 Correct 461 ms 420 KB Output is correct
17 Correct 491 ms 420 KB Output is correct
18 Correct 392 ms 636 KB Output is correct
19 Correct 455 ms 508 KB Output is correct
20 Correct 401 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 570 ms 676 KB Output is correct
2 Correct 422 ms 624 KB Output is correct
3 Correct 793 ms 420 KB Output is correct
4 Correct 651 ms 420 KB Output is correct
5 Correct 502 ms 420 KB Output is correct
6 Correct 448 ms 640 KB Output is correct
7 Correct 480 ms 548 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 453 ms 544 KB Output is correct
12 Correct 465 ms 544 KB Output is correct
13 Correct 820 ms 512 KB Output is correct
14 Correct 615 ms 508 KB Output is correct
15 Correct 604 ms 484 KB Output is correct
16 Correct 410 ms 544 KB Output is correct
17 Correct 466 ms 420 KB Output is correct
18 Correct 462 ms 716 KB Output is correct
19 Correct 406 ms 756 KB Output is correct
20 Correct 413 ms 548 KB Output is correct
21 Correct 53 ms 440 KB Output is correct
22 Correct 55 ms 544 KB Output is correct
23 Correct 100 ms 544 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 5 ms 492 KB Output is correct
26 Correct 5 ms 500 KB Output is correct
27 Correct 4 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 437 ms 508 KB Output is correct
30 Correct 518 ms 512 KB Output is correct
31 Correct 461 ms 508 KB Output is correct
32 Correct 470 ms 420 KB Output is correct
33 Correct 475 ms 420 KB Output is correct
34 Correct 304 ms 672 KB Output is correct
35 Correct 428 ms 776 KB Output is correct
36 Correct 381 ms 748 KB Output is correct
37 Correct 468 ms 636 KB Output is correct
38 Correct 424 ms 600 KB Output is correct
39 Correct 452 ms 728 KB Output is correct
40 Correct 455 ms 664 KB Output is correct
41 Correct 439 ms 644 KB Output is correct
42 Correct 62 ms 572 KB Output is correct
43 Correct 103 ms 532 KB Output is correct
44 Correct 135 ms 544 KB Output is correct
45 Correct 160 ms 548 KB Output is correct
46 Correct 278 ms 544 KB Output is correct
47 Correct 319 ms 544 KB Output is correct
48 Correct 71 ms 548 KB Output is correct
49 Correct 48 ms 744 KB Output is correct