Submission #821863

# Submission time Handle Problem Language Result Execution time Memory
821863 2023-08-11T19:33:43 Z TB_ Stations (IOI20_stations) C++17
100 / 100
751 ms 808 KB
#include <bits/stdc++.h>
using namespace std;

// #undef _GLIBCXX_DEBUG                // disable run-time bound checking, etc
// #pragma GCC optimize("Ofast,inline") // Ofast = O3,fast-math,allow-store-data-races,no-protect-parens
// #pragma GCC optimize ("unroll-loops")

// #pragma GCC target("bmi,bmi2,lzcnt,popcnt")                      // bit manipulation
// #pragma GCC target("movbe")                                      // byte swap
// #pragma GCC target("aes,pclmul,rdrnd")                           // encryption
// #pragma GCC target("avx,avx2,f16c,fma,sse3,ssse3,sse4.1,sse4.2") // SIMD

// #include <bits/extc++.h>
// using namespace __gnu_pbds;
// template<class T>using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
// template<class T>using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define INF (ll)1e9+7
#define fo(i, n) for(int i=0;i<((ll)n);i++)
#define deb(x) cout << #x << " = " << x << endl;
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LSOne(S) ((S) & (-S))
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
inline int readint(){ int v = 0; char c; while((c = getchar()) != EOF && c != ' ' && c != '\n'){ v *= 10; v += c - '0'; } return v; }
inline int readintsigned() { int v = 0; int sign = 1; char c = getchar(); if (c == '-') { sign = -1; } else { v += c - '0'; } while ((c = getchar()) != EOF && c != ' ' && c != '\n') { v *= 10; v += c - '0'; } return v * sign; }
inline string readstring() { string s; char c; while ((c = getchar()) != EOF && c != '\n' && c != ' ') { s.push_back(c); } return s; }
template <class result_t=std::chrono::milliseconds,class clock_t=std::chrono::steady_clock,class duration_t = std::chrono::milliseconds>
auto since(std::chrono::time_point<clock_t, duration_t> const& start){return std::chrono::duration_cast<result_t>(clock_t::now() - start);}
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vpii> vvpii;
typedef vector<vpl> vvpl;

int index2 = 0;
vvl adj;
vi labels2;

void dfs(int u, int last = -1, bool odd = 0){
	if(odd) labels2[u] = index2++;
    for(auto v : adj[u]){
        if(v == last) continue;
        dfs(v, u, !odd);
    }
	if(!odd) labels2[u] = index2++;
}

vi label(int n, int k, vi u, vi v) {
	labels2.assign(n, 0);
	adj.assign(n, {});
	fo(i, n-1){
		adj[u[i]].pb(v[i]);
		adj[v[i]].pb(u[i]);
	}
	index2 = 0;
	dfs(0);
	return labels2;
}

int find_next_station(int s, int t, vi c) {
	bool isFirst = true;
	sort(all(c));

	fo(i, c.size()) 
		if(c[i] < s) isFirst = false;
	
	
	if(isFirst){
		if(t<s || t>=c[c.size()-1]) return c[c.size()-1];
		fo(i, c.size()) if(c[i] >= t) return c[i];
		throw runtime_error("Should not get here!");
	}
	c.pb(s);
	if(t>s) return c[0];
	fo(i, c.size()-1) if(t >= c[i] && t < c[i+1]) return c[i];

	return c[0];
}



// static int max_label = 0;
// static int r, n, k, q;
// static std::vector<int> u, v, labels, answers;
// static std::map<int, int> reverse_labels;
// static std::vector<std::vector<int>> adjlist;
// static int s, t, w;
// static std::vector<int> c;

// int main() {
// 	assert(scanf("%d", &r) == 1);
// 	for (int tc = 0; tc < r; tc++) {
// 		assert(scanf("%d%d", &n, &k) == 2);
// 		u.resize(n - 1);
// 		v.resize(n - 1);
// 		adjlist.clear();
// 		adjlist.resize(n);
// 		for (int i = 0; i < n - 1; i++) {
// 			assert(scanf("%d%d", &u[i], &v[i]) == 2);
// 			adjlist[u[i]].push_back(v[i]);
// 			adjlist[v[i]].push_back(u[i]);
// 		}
// 		labels = label(n, k, u, v);
// 		if ((int)labels.size() != n) {
// 			printf("Number of labels not equal to %d\n", n);
// 			exit(0);
// 		}
// 		reverse_labels.clear();
// 		for (int i = 0; i < n; i++) {
// 			if (labels[i] < 0 || labels[i] > k) {
// 				printf("Label not in range 0 to %d\n", k);
// 				exit(0);
// 			}
// 			if (reverse_labels.find(labels[i]) != reverse_labels.end()) {
// 				printf("Labels not unique\n");
// 				exit(0);
// 			}
// 			reverse_labels[labels[i]] = i;
// 			if (labels[i] > max_label) {
// 				max_label = labels[i];
// 			}
// 		}
// 		assert(scanf("%d", &q) == 1);
// 		for (int i = 0; i < q; i++) {
// 			assert(scanf("%d%d%d", &s, &t, &w) == 3);
// 			c.clear();
// 			for (int v : adjlist[s]) {
// 				c.push_back(labels[v]);
// 			}
// 			std::sort(c.begin(), c.end());
// 			int answer = find_next_station(labels[s], labels[t], c);
// 			if (!std::binary_search(c.begin(), c.end(), answer)) {
// 				printf("Label %d returned by find_next_station not found in c\n", answer);
// 				exit(0);
// 			}
// 			answers.push_back(reverse_labels[answer]);
// 		}
// 	}
// 	printf("%d\n", max_label);
// 	for (int index : answers) {
// 		printf("%d\n", index);
// 	}
// 	exit(0);
// }

# Verdict Execution time Memory Grader output
1 Correct 500 ms 652 KB Output is correct
2 Correct 427 ms 680 KB Output is correct
3 Correct 634 ms 432 KB Output is correct
4 Correct 505 ms 500 KB Output is correct
5 Correct 447 ms 416 KB Output is correct
6 Correct 432 ms 636 KB Output is correct
7 Correct 374 ms 608 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 2 ms 488 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 465 ms 624 KB Output is correct
2 Correct 428 ms 504 KB Output is correct
3 Correct 690 ms 416 KB Output is correct
4 Correct 338 ms 504 KB Output is correct
5 Correct 465 ms 472 KB Output is correct
6 Correct 368 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 448 ms 684 KB Output is correct
2 Correct 396 ms 740 KB Output is correct
3 Correct 751 ms 504 KB Output is correct
4 Correct 535 ms 420 KB Output is correct
5 Correct 495 ms 416 KB Output is correct
6 Correct 381 ms 664 KB Output is correct
7 Correct 315 ms 632 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 458 ms 504 KB Output is correct
12 Correct 361 ms 716 KB Output is correct
13 Correct 371 ms 668 KB Output is correct
14 Correct 411 ms 500 KB Output is correct
15 Correct 43 ms 492 KB Output is correct
16 Correct 59 ms 548 KB Output is correct
17 Correct 86 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 751 ms 504 KB Output is correct
2 Correct 453 ms 508 KB Output is correct
3 Correct 586 ms 508 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 0 ms 492 KB Output is correct
7 Correct 353 ms 504 KB Output is correct
8 Correct 704 ms 420 KB Output is correct
9 Correct 519 ms 492 KB Output is correct
10 Correct 411 ms 508 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
12 Correct 3 ms 472 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 363 ms 504 KB Output is correct
17 Correct 443 ms 508 KB Output is correct
18 Correct 484 ms 504 KB Output is correct
19 Correct 484 ms 484 KB Output is correct
20 Correct 434 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 378 ms 676 KB Output is correct
2 Correct 354 ms 676 KB Output is correct
3 Correct 563 ms 488 KB Output is correct
4 Correct 573 ms 512 KB Output is correct
5 Correct 458 ms 500 KB Output is correct
6 Correct 437 ms 612 KB Output is correct
7 Correct 327 ms 544 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 1 ms 500 KB Output is correct
11 Correct 313 ms 636 KB Output is correct
12 Correct 440 ms 504 KB Output is correct
13 Correct 695 ms 500 KB Output is correct
14 Correct 441 ms 500 KB Output is correct
15 Correct 411 ms 420 KB Output is correct
16 Correct 373 ms 508 KB Output is correct
17 Correct 488 ms 416 KB Output is correct
18 Correct 369 ms 620 KB Output is correct
19 Correct 351 ms 624 KB Output is correct
20 Correct 261 ms 504 KB Output is correct
21 Correct 37 ms 488 KB Output is correct
22 Correct 55 ms 620 KB Output is correct
23 Correct 76 ms 508 KB Output is correct
24 Correct 3 ms 500 KB Output is correct
25 Correct 3 ms 500 KB Output is correct
26 Correct 4 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 1 ms 500 KB Output is correct
29 Correct 313 ms 416 KB Output is correct
30 Correct 377 ms 420 KB Output is correct
31 Correct 378 ms 508 KB Output is correct
32 Correct 428 ms 504 KB Output is correct
33 Correct 295 ms 420 KB Output is correct
34 Correct 277 ms 640 KB Output is correct
35 Correct 284 ms 740 KB Output is correct
36 Correct 397 ms 760 KB Output is correct
37 Correct 442 ms 720 KB Output is correct
38 Correct 459 ms 628 KB Output is correct
39 Correct 390 ms 716 KB Output is correct
40 Correct 333 ms 720 KB Output is correct
41 Correct 454 ms 724 KB Output is correct
42 Correct 57 ms 732 KB Output is correct
43 Correct 112 ms 508 KB Output is correct
44 Correct 129 ms 600 KB Output is correct
45 Correct 158 ms 636 KB Output is correct
46 Correct 178 ms 544 KB Output is correct
47 Correct 254 ms 544 KB Output is correct
48 Correct 61 ms 808 KB Output is correct
49 Correct 40 ms 784 KB Output is correct