Submission #592710

# Submission time Handle Problem Language Result Execution time Memory
592710 2022-07-09T13:44:17 Z Blagojce City Mapping (NOI18_citymapping) C++11
91.98 / 100
10 ms 8404 KB
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define st first
#define nd second
#define pb push_back
#define pq priority_queue
#define all(x) begin(x), end(x)
 
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
 
const int mxn = 1003;
mt19937 _rand(time(NULL));
clock_t z;
 
#include "citymapping.h"
 
ll dist[mxn][mxn];/*
ll get_distance(int x, int y){
	cout<<"? "<<x<<' '<<y<<endl;
	ll ret;
	cin >> ret;
	return ret;
}*/
ll ask(int x, int y){
	if(x != y && dist[x][y] == 0){
		dist[x][y] = dist[y][x] = get_distance(x+1, y+1);
	}
	return dist[x][y];
}
vector<int> g;
int R1, R2;
 
 
int AA[mxn], BB[mxn], WW[mxn];
int edge_id = 0;
 
void add_edge(int x, int y, int w){
	AA[edge_id] = x;
	BB[edge_id] = y;
	WW[edge_id] = w;
	edge_id ++;
}
 
 
 
 
void decompose(vector<int> v){
	int r1 = v[_rand() % (int)v.size()];
	g = v;
	
	if((int)g.size() <= 1) return;
	
	for(auto u : g){
		ask(u, r1);
	}
	int r2 = r1;
	for(auto u : g){
		if(dist[r1][u] > dist[r1][r2]){
			r2 = u;
		}
	}
	for(auto u : g){
		ask(u, r2);
	}
	R1 = r1;
	R2 = r2;
	
	sort(all(g), [](const int &i, const int &j){
		return dist[R1][i] < dist[R1][j];
	});
	
	vector<int> diam;
	for(auto u : g){
		if(dist[r1][u] + dist[u][r2] == dist[r1][r2]){
			diam.pb(u);
		}
	}
	
	fr(i, 1, (int)diam.size()){
		add_edge(diam[i-1], diam[i], dist[r1][diam[i]] - dist[r1][diam[i-1]]);
	}
	vector<int> sub[(int)diam.size()];
	fr(i, 0, (int)diam.size()){
		sub[i].pb(diam[i]);
	}
	
	for(auto u : g){
		if(dist[r1][u] + dist[u][r2] == dist[r1][r2]) continue;
		fr(i, 0, (int)diam.size()){
			auto d = diam[i];
			if(dist[r1][u] - dist[r2][u] == dist[r1][d] - dist[r2][d]){
				sub[i].pb(u);
				break;
			}
		}
	}
	
	fr(i, 0, (int)diam.size()){
		decompose(sub[i]);
	}
}
 
void find_roads(int N, int Q, int A[], int B[], int W[]) {
	vector<int> v;
	fr(i, 0, N) v.pb(i);
	
	decompose(v);
	fr(i, 0, N-1){
		A[i] = AA[i] + 1;
		B[i] = BB[i] + 1;
		W[i] = WW[i];
	}
	return;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 6996 KB Correct: 2115 out of 500000 queries used.
2 Correct 5 ms 7508 KB Correct: 2734 out of 500000 queries used.
3 Correct 6 ms 8132 KB Correct: 6953 out of 500000 queries used.
4 Correct 6 ms 8276 KB Correct: 6751 out of 500000 queries used.
5 Correct 6 ms 8020 KB Correct: 6001 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 5 ms 6996 KB Correct: 2115 out of 500000 queries used.
2 Correct 5 ms 7508 KB Correct: 2734 out of 500000 queries used.
3 Correct 6 ms 8132 KB Correct: 6953 out of 500000 queries used.
4 Correct 6 ms 8276 KB Correct: 6751 out of 500000 queries used.
5 Correct 6 ms 8020 KB Correct: 6001 out of 500000 queries used.
6 Correct 5 ms 8276 KB Correct: 2502 out of 500000 queries used.
7 Correct 5 ms 7896 KB Correct: 4203 out of 500000 queries used.
8 Correct 5 ms 8148 KB Correct: 6480 out of 500000 queries used.
9 Correct 8 ms 8276 KB Correct: 6804 out of 500000 queries used.
10 Correct 6 ms 8276 KB Correct: 5977 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5668 KB Correct: 2098 out of 12000 queries used.
2 Correct 6 ms 6612 KB Correct: 2028 out of 12000 queries used.
3 Correct 8 ms 8252 KB Correct: 2566 out of 12000 queries used.
4 Correct 7 ms 7124 KB Correct: 2367 out of 12000 queries used.
5 Correct 7 ms 6784 KB Correct: 2518 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5668 KB Correct: 2098 out of 12000 queries used.
2 Correct 6 ms 6612 KB Correct: 2028 out of 12000 queries used.
3 Correct 8 ms 8252 KB Correct: 2566 out of 12000 queries used.
4 Correct 7 ms 7124 KB Correct: 2367 out of 12000 queries used.
5 Correct 7 ms 6784 KB Correct: 2518 out of 12000 queries used.
6 Correct 4 ms 4948 KB Correct: 2021 out of 12000 queries used.
7 Correct 4 ms 5332 KB Correct: 2289 out of 12000 queries used.
8 Correct 4 ms 6228 KB Correct: 2643 out of 12000 queries used.
9 Correct 5 ms 6996 KB Correct: 2121 out of 12000 queries used.
10 Correct 5 ms 7472 KB Correct: 2437 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 5 ms 6996 KB Correct: 2115 out of 500000 queries used.
2 Correct 5 ms 7508 KB Correct: 2734 out of 500000 queries used.
3 Correct 6 ms 8132 KB Correct: 6953 out of 500000 queries used.
4 Correct 6 ms 8276 KB Correct: 6751 out of 500000 queries used.
5 Correct 6 ms 8020 KB Correct: 6001 out of 500000 queries used.
6 Correct 5 ms 8276 KB Correct: 2502 out of 500000 queries used.
7 Correct 5 ms 7896 KB Correct: 4203 out of 500000 queries used.
8 Correct 5 ms 8148 KB Correct: 6480 out of 500000 queries used.
9 Correct 8 ms 8276 KB Correct: 6804 out of 500000 queries used.
10 Correct 6 ms 8276 KB Correct: 5977 out of 500000 queries used.
11 Correct 4 ms 5668 KB Correct: 2098 out of 12000 queries used.
12 Correct 6 ms 6612 KB Correct: 2028 out of 12000 queries used.
13 Correct 8 ms 8252 KB Correct: 2566 out of 12000 queries used.
14 Correct 7 ms 7124 KB Correct: 2367 out of 12000 queries used.
15 Correct 7 ms 6784 KB Correct: 2518 out of 12000 queries used.
16 Correct 4 ms 4948 KB Correct: 2021 out of 12000 queries used.
17 Correct 4 ms 5332 KB Correct: 2289 out of 12000 queries used.
18 Correct 4 ms 6228 KB Correct: 2643 out of 12000 queries used.
19 Correct 5 ms 6996 KB Correct: 2121 out of 12000 queries used.
20 Correct 5 ms 7472 KB Correct: 2437 out of 12000 queries used.
21 Correct 5 ms 7764 KB Correct: 2860 out of 25000 queries used.
22 Correct 6 ms 7892 KB Correct: 4489 out of 25000 queries used.
23 Correct 5 ms 7636 KB Correct: 2842 out of 25000 queries used.
24 Correct 7 ms 8020 KB Correct: 3912 out of 25000 queries used.
25 Correct 6 ms 8288 KB Correct: 6208 out of 25000 queries used.
26 Correct 8 ms 8112 KB Correct: 6226 out of 25000 queries used.
27 Correct 6 ms 8148 KB Correct: 6258 out of 25000 queries used.
28 Correct 6 ms 8148 KB Correct: 6704 out of 25000 queries used.
29 Correct 7 ms 8268 KB Correct: 6687 out of 25000 queries used.
30 Correct 7 ms 8148 KB Correct: 6247 out of 25000 queries used.
31 Correct 9 ms 8276 KB Correct: 6985 out of 25000 queries used.
32 Correct 4 ms 4948 KB Correct: 2162 out of 25000 queries used.
33 Correct 6 ms 8276 KB Correct: 7075 out of 25000 queries used.
34 Correct 6 ms 8276 KB Correct: 6941 out of 25000 queries used.
35 Correct 6 ms 8276 KB Correct: 6794 out of 25000 queries used.
36 Correct 6 ms 8080 KB Correct: 6914 out of 25000 queries used.
37 Correct 6 ms 8276 KB Correct: 7181 out of 25000 queries used.
38 Correct 6 ms 8276 KB Correct: 6983 out of 25000 queries used.
39 Correct 6 ms 8276 KB Correct: 6851 out of 25000 queries used.
40 Correct 7 ms 8276 KB Correct: 6819 out of 25000 queries used.
41 Correct 6 ms 8148 KB Correct: 6769 out of 25000 queries used.
42 Correct 6 ms 8148 KB Correct: 6881 out of 25000 queries used.
43 Correct 6 ms 8276 KB Correct: 2351 out of 25000 queries used.
44 Correct 8 ms 8148 KB Correct: 6731 out of 25000 queries used.
45 Correct 8 ms 8276 KB Correct: 6747 out of 25000 queries used.
46 Correct 8 ms 8148 KB Correct: 7295 out of 25000 queries used.
47 Correct 10 ms 8144 KB Correct: 6883 out of 25000 queries used.
48 Correct 8 ms 8404 KB Correct: 6886 out of 25000 queries used.
49 Correct 6 ms 8244 KB Correct: 6755 out of 25000 queries used.
50 Correct 6 ms 8276 KB Correct: 6773 out of 25000 queries used.
51 Correct 7 ms 8148 KB Correct: 6872 out of 25000 queries used.
52 Correct 6 ms 8164 KB Correct: 6911 out of 25000 queries used.
53 Correct 6 ms 8276 KB Correct: 6898 out of 25000 queries used.
54 Correct 6 ms 8340 KB Correct: 7332 out of 25000 queries used.
55 Correct 6 ms 8148 KB Correct: 6848 out of 25000 queries used.
56 Correct 8 ms 8148 KB Correct: 6895 out of 25000 queries used.
57 Correct 7 ms 8276 KB Correct: 6775 out of 25000 queries used.
58 Correct 7 ms 8212 KB Correct: 7420 out of 25000 queries used.
59 Correct 6 ms 8148 KB Correct: 6768 out of 25000 queries used.
60 Correct 5 ms 7892 KB Correct: 4185 out of 25000 queries used.
61 Correct 6 ms 7892 KB Correct: 5696 out of 25000 queries used.
62 Correct 6 ms 7764 KB Correct: 5309 out of 25000 queries used.
63 Correct 5 ms 7660 KB Correct: 4161 out of 25000 queries used.
64 Correct 6 ms 7636 KB Correct: 4686 out of 25000 queries used.
65 Correct 5 ms 7508 KB Correct: 2823 out of 25000 queries used.
66 Correct 6 ms 7636 KB Correct: 4293 out of 25000 queries used.
67 Correct 6 ms 7636 KB Correct: 5542 out of 25000 queries used.
68 Correct 5 ms 6996 KB Correct: 3296 out of 25000 queries used.
69 Correct 6 ms 7892 KB Correct: 5344 out of 25000 queries used.
70 Correct 7 ms 7892 KB Correct: 2661 out of 25000 queries used.