Submission #962922

# Submission time Handle Problem Language Result Execution time Memory
962922 2024-04-14T09:47:24 Z biximo Stations (IOI20_stations) C++17
65.3244 / 100
685 ms 1660 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define N 1005
vector<int> adj[N];
int n, ids[N], sz[N], id;
void dfs(int c, int pr) {
	ids[c] = id++;
	sz[c] = 1;
	for(int i: adj[c]) {
		if(i == pr) continue;
		dfs(i, c);
		sz[c] += sz[i];
	}
}
vector<int> euler_tree() {
	id = 0;
	dfs(0, -1);
	vector<int> ans(n);
	for(int i = 0; i < n; i ++) {
		sz[i] --;
		ans[i] = sz[i]*1000+ids[i];
	}
	return ans;
}
vector<int> nddds;
void DFS(int c, int pr) {
	nddds.push_back(c);
	for(int i: adj[c]) {
		if(i == pr) continue;
		DFS(i, c);
	}
}
vector<int> flatten() {
	nddds.clear();
	for(int i = 0; i < n; i ++) {
		if(adj[i].size() == 1) {
			DFS(i, -1);
			vector<int> nds = nddds;
			vector<int> ans(n);
			for(int j = 0; j < n; j ++) {
				ans[nds[j]] = j;
			}
			return ans;
		}
	}
	return vector<int>();
	assert(0);
}
std::vector<int> label(int ngb, int k, std::vector<int> u, std::vector<int> v) {
	n = ngb;
	for(auto&i: adj) i.clear();
	for(int i = 0; i < n-1; i ++) {
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	int ms = 0;
	for(auto&i: adj) ms = max(ms, (int)i.size());
	if(k >= 1000000) {
		return euler_tree();
	} 
	for(int i = 0; i < n-1; i ++) {
		if(u[i] == i+1 && v[i] == i/2 || u[i] == i/2 && v[i] == i+1) continue;
		return flatten();
	}
	vector<int> nds;
	for(int i = 0; i < n; i ++) nds.push_back(i);
	return nds;
}
struct Nd {
	int id, sz;
	Nd(int i) : id(i/1000), sz(i%1000) {
	}
};
int findEuler(int s, int t, vector<int> c) {
	int sid = s%1000, ssz = s/1000;
	int tid = t%1000, tsz = t/1000;
	if(sid <= tid && tid <= sid + ssz) {
		for(int i: c) {
			int nid = i%1000, nsz = i/1000;
			if(nid <= tid && tid <= nid + nsz) {
				return i;
			}
		}	
		assert(0);
	}
	for(int i: c) {
		int nsz = i/1000;
		if(nsz >= ssz) {
			return i;
		}
	}
	assert(0);
}
int findFlat(int s, int t, vector<int> c) {
	if(s < t) {
		if(c.size() == 1) return c[0];
		return c[1];
	} else {
		return c[0];
	}
}
int ds[N], pr[N];
int findWeird(int s, int t, vector<int> c) {
	for(auto&i: adj) i.clear();
	for(int i = 0; i < max(s,t); i ++) {
		adj[i+1].push_back(i/2);
		adj[i/2].push_back(i+1);
	}
	for(auto&i: ds) i = N;
	queue<int> que;
	que.push(t); ds[t] = 0; pr[t] = 0;
	while(que.size()) {
		int c = que.front(); que.pop();
		for(int i: adj[c]) {
			if(ds[i] > ds[c]+1) {
				ds[i] = ds[c]+1;
				pr[i] = c;
				que.push(i);
			}
		}
	}
	return pr[s];
}
int find_next_station(int s, int t, std::vector<int> c) {
	int mv = max(s, t);
	for(int i: c) mv = max(mv, i);
	if(mv >= 1000) {
		return findEuler(s,t,c);
	}
	if(c.size() == 1 && (c[0] == s+1 || c[0] == s-1)) {
		return findFlat(s,t,c);
	}
	if(c.size() == 2 && c[0] == s-1 && c[1] == s+1) {
		return findFlat(s,t,c);
	}
	return findWeird(s,t,c);
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:63:18: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   63 |   if(u[i] == i+1 && v[i] == i/2 || u[i] == i/2 && v[i] == i+1) continue;
stations.cpp: In function 'int findEuler(int, int, std::vector<int>)':
stations.cpp:77:20: warning: unused variable 'tsz' [-Wunused-variable]
   77 |  int tid = t%1000, tsz = t/1000;
      |                    ^~~
# Verdict Execution time Memory Grader output
1 Correct 347 ms 916 KB Output is correct
2 Correct 302 ms 932 KB Output is correct
3 Correct 561 ms 684 KB Output is correct
4 Correct 448 ms 876 KB Output is correct
5 Correct 420 ms 876 KB Output is correct
6 Correct 297 ms 916 KB Output is correct
7 Correct 277 ms 684 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 685 ms 1012 KB Output is correct
2 Correct 468 ms 1096 KB Output is correct
3 Correct 553 ms 684 KB Output is correct
4 Correct 486 ms 684 KB Output is correct
5 Correct 497 ms 684 KB Output is correct
6 Correct 633 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 326 ms 948 KB Output is correct
2 Correct 273 ms 948 KB Output is correct
3 Correct 521 ms 800 KB Output is correct
4 Correct 401 ms 684 KB Output is correct
5 Correct 359 ms 684 KB Output is correct
6 Correct 292 ms 944 KB Output is correct
7 Correct 285 ms 684 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 358 ms 800 KB Output is correct
12 Correct 286 ms 1316 KB Output is correct
13 Correct 291 ms 1296 KB Output is correct
14 Correct 285 ms 684 KB Output is correct
15 Correct 35 ms 908 KB Output is correct
16 Correct 38 ms 936 KB Output is correct
17 Correct 59 ms 916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 537 ms 1060 KB Output is correct
2 Correct 423 ms 940 KB Output is correct
3 Correct 369 ms 684 KB Output is correct
4 Correct 2 ms 764 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 0 ms 768 KB Output is correct
7 Correct 375 ms 684 KB Output is correct
8 Correct 513 ms 684 KB Output is correct
9 Correct 447 ms 688 KB Output is correct
10 Correct 375 ms 876 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 1032 KB Output is correct
14 Correct 3 ms 764 KB Output is correct
15 Correct 0 ms 768 KB Output is correct
16 Correct 310 ms 684 KB Output is correct
17 Correct 309 ms 868 KB Output is correct
18 Correct 325 ms 936 KB Output is correct
19 Correct 333 ms 684 KB Output is correct
20 Correct 319 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 332 ms 944 KB Partially correct
2 Partially correct 321 ms 940 KB Partially correct
3 Correct 595 ms 684 KB Output is correct
4 Partially correct 426 ms 940 KB Partially correct
5 Partially correct 390 ms 684 KB Partially correct
6 Partially correct 281 ms 952 KB Partially correct
7 Partially correct 302 ms 684 KB Partially correct
8 Partially correct 1 ms 764 KB Partially correct
9 Partially correct 2 ms 768 KB Partially correct
10 Partially correct 0 ms 768 KB Partially correct
11 Partially correct 303 ms 876 KB Partially correct
12 Partially correct 362 ms 844 KB Partially correct
13 Correct 569 ms 684 KB Output is correct
14 Partially correct 434 ms 684 KB Partially correct
15 Partially correct 380 ms 848 KB Partially correct
16 Partially correct 298 ms 684 KB Partially correct
17 Partially correct 388 ms 684 KB Partially correct
18 Partially correct 298 ms 1288 KB Partially correct
19 Partially correct 318 ms 1552 KB Partially correct
20 Partially correct 318 ms 688 KB Partially correct
21 Partially correct 38 ms 872 KB Partially correct
22 Partially correct 49 ms 1176 KB Partially correct
23 Partially correct 64 ms 924 KB Partially correct
24 Partially correct 4 ms 768 KB Partially correct
25 Partially correct 5 ms 768 KB Partially correct
26 Partially correct 3 ms 768 KB Partially correct
27 Partially correct 3 ms 768 KB Partially correct
28 Partially correct 2 ms 764 KB Partially correct
29 Partially correct 303 ms 684 KB Partially correct
30 Partially correct 326 ms 684 KB Partially correct
31 Partially correct 324 ms 684 KB Partially correct
32 Partially correct 336 ms 684 KB Partially correct
33 Partially correct 330 ms 940 KB Partially correct
34 Partially correct 207 ms 928 KB Partially correct
35 Partially correct 293 ms 1324 KB Partially correct
36 Partially correct 305 ms 1196 KB Partially correct
37 Partially correct 301 ms 1168 KB Partially correct
38 Partially correct 284 ms 1044 KB Partially correct
39 Partially correct 294 ms 1044 KB Partially correct
40 Partially correct 302 ms 1176 KB Partially correct
41 Partially correct 301 ms 1028 KB Partially correct
42 Partially correct 40 ms 860 KB Partially correct
43 Partially correct 62 ms 888 KB Partially correct
44 Partially correct 82 ms 956 KB Partially correct
45 Partially correct 107 ms 900 KB Partially correct
46 Partially correct 206 ms 872 KB Partially correct
47 Partially correct 190 ms 904 KB Partially correct
48 Partially correct 34 ms 1476 KB Partially correct
49 Partially correct 28 ms 1660 KB Partially correct