Submission #592718

# Submission time Handle Problem Language Result Execution time Memory
592718 2022-07-09T13:57:40 Z Blagojce City Mapping (NOI18_citymapping) C++11
91.82 / 100
9 ms 8336 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);
	}
	
	R1 = r1;
	sort(all(g), [](const int &i, const int &j){
		return dist[R1][i] < dist[R1][j];
	});
	int r2 = g.back();
	
	for(auto u : g){
		ask(u, r2);
	}
	
	
	
	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()){
		int d = diam[i];
		for(auto s : sub[i]){
			dist[d][s] = dist[s][d] = dist[r1][s] - dist[r1][d];
		}
	}
	
	
	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 8148 KB Correct: 2343 out of 500000 queries used.
2 Correct 7 ms 8168 KB Correct: 2421 out of 500000 queries used.
3 Correct 7 ms 8148 KB Correct: 5526 out of 500000 queries used.
4 Correct 6 ms 8148 KB Correct: 6181 out of 500000 queries used.
5 Correct 7 ms 8148 KB Correct: 4197 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8148 KB Correct: 2343 out of 500000 queries used.
2 Correct 7 ms 8168 KB Correct: 2421 out of 500000 queries used.
3 Correct 7 ms 8148 KB Correct: 5526 out of 500000 queries used.
4 Correct 6 ms 8148 KB Correct: 6181 out of 500000 queries used.
5 Correct 7 ms 8148 KB Correct: 4197 out of 500000 queries used.
6 Correct 5 ms 7892 KB Correct: 2699 out of 500000 queries used.
7 Correct 5 ms 8276 KB Correct: 4702 out of 500000 queries used.
8 Correct 5 ms 8276 KB Correct: 5556 out of 500000 queries used.
9 Correct 6 ms 8276 KB Correct: 6040 out of 500000 queries used.
10 Correct 6 ms 8148 KB Correct: 4231 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7508 KB Correct: 2193 out of 12000 queries used.
2 Correct 5 ms 7636 KB Correct: 2505 out of 12000 queries used.
3 Correct 7 ms 7636 KB Correct: 1997 out of 12000 queries used.
4 Correct 6 ms 8276 KB Correct: 2318 out of 12000 queries used.
5 Correct 7 ms 7892 KB Correct: 2071 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7508 KB Correct: 2193 out of 12000 queries used.
2 Correct 5 ms 7636 KB Correct: 2505 out of 12000 queries used.
3 Correct 7 ms 7636 KB Correct: 1997 out of 12000 queries used.
4 Correct 6 ms 8276 KB Correct: 2318 out of 12000 queries used.
5 Correct 7 ms 7892 KB Correct: 2071 out of 12000 queries used.
6 Correct 6 ms 6996 KB Correct: 2157 out of 12000 queries used.
7 Correct 5 ms 7252 KB Correct: 2647 out of 12000 queries used.
8 Correct 7 ms 8192 KB Correct: 2717 out of 12000 queries used.
9 Correct 5 ms 8020 KB Correct: 2645 out of 12000 queries used.
10 Correct 5 ms 6996 KB Correct: 2087 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8148 KB Correct: 2343 out of 500000 queries used.
2 Correct 7 ms 8168 KB Correct: 2421 out of 500000 queries used.
3 Correct 7 ms 8148 KB Correct: 5526 out of 500000 queries used.
4 Correct 6 ms 8148 KB Correct: 6181 out of 500000 queries used.
5 Correct 7 ms 8148 KB Correct: 4197 out of 500000 queries used.
6 Correct 5 ms 7892 KB Correct: 2699 out of 500000 queries used.
7 Correct 5 ms 8276 KB Correct: 4702 out of 500000 queries used.
8 Correct 5 ms 8276 KB Correct: 5556 out of 500000 queries used.
9 Correct 6 ms 8276 KB Correct: 6040 out of 500000 queries used.
10 Correct 6 ms 8148 KB Correct: 4231 out of 500000 queries used.
11 Correct 7 ms 7508 KB Correct: 2193 out of 12000 queries used.
12 Correct 5 ms 7636 KB Correct: 2505 out of 12000 queries used.
13 Correct 7 ms 7636 KB Correct: 1997 out of 12000 queries used.
14 Correct 6 ms 8276 KB Correct: 2318 out of 12000 queries used.
15 Correct 7 ms 7892 KB Correct: 2071 out of 12000 queries used.
16 Correct 6 ms 6996 KB Correct: 2157 out of 12000 queries used.
17 Correct 5 ms 7252 KB Correct: 2647 out of 12000 queries used.
18 Correct 7 ms 8192 KB Correct: 2717 out of 12000 queries used.
19 Correct 5 ms 8020 KB Correct: 2645 out of 12000 queries used.
20 Correct 5 ms 6996 KB Correct: 2087 out of 12000 queries used.
21 Correct 4 ms 6612 KB Correct: 2257 out of 25000 queries used.
22 Correct 6 ms 8148 KB Correct: 3747 out of 25000 queries used.
23 Correct 7 ms 8276 KB Correct: 6180 out of 25000 queries used.
24 Correct 5 ms 7764 KB Correct: 2497 out of 25000 queries used.
25 Correct 7 ms 8276 KB Correct: 5663 out of 25000 queries used.
26 Correct 8 ms 8148 KB Correct: 5422 out of 25000 queries used.
27 Correct 6 ms 8276 KB Correct: 5358 out of 25000 queries used.
28 Correct 6 ms 8276 KB Correct: 5774 out of 25000 queries used.
29 Correct 6 ms 8324 KB Correct: 5591 out of 25000 queries used.
30 Correct 6 ms 8276 KB Correct: 6109 out of 25000 queries used.
31 Correct 7 ms 8336 KB Correct: 6193 out of 25000 queries used.
32 Correct 5 ms 7508 KB Correct: 2269 out of 25000 queries used.
33 Correct 6 ms 8276 KB Correct: 6019 out of 25000 queries used.
34 Correct 7 ms 8276 KB Correct: 6032 out of 25000 queries used.
35 Correct 6 ms 8276 KB Correct: 6093 out of 25000 queries used.
36 Correct 7 ms 8276 KB Correct: 6101 out of 25000 queries used.
37 Correct 6 ms 8276 KB Correct: 6168 out of 25000 queries used.
38 Correct 6 ms 8276 KB Correct: 6544 out of 25000 queries used.
39 Correct 6 ms 8256 KB Correct: 6168 out of 25000 queries used.
40 Correct 6 ms 8312 KB Correct: 6198 out of 25000 queries used.
41 Correct 6 ms 8276 KB Correct: 6104 out of 25000 queries used.
42 Correct 7 ms 8300 KB Correct: 6144 out of 25000 queries used.
43 Correct 5 ms 7764 KB Correct: 2309 out of 25000 queries used.
44 Correct 8 ms 8148 KB Correct: 6076 out of 25000 queries used.
45 Correct 6 ms 8148 KB Correct: 6037 out of 25000 queries used.
46 Correct 9 ms 8176 KB Correct: 6414 out of 25000 queries used.
47 Correct 6 ms 8276 KB Correct: 6053 out of 25000 queries used.
48 Correct 7 ms 8276 KB Correct: 6093 out of 25000 queries used.
49 Correct 6 ms 8252 KB Correct: 6133 out of 25000 queries used.
50 Correct 6 ms 8276 KB Correct: 6165 out of 25000 queries used.
51 Correct 7 ms 8276 KB Correct: 6089 out of 25000 queries used.
52 Correct 6 ms 8328 KB Correct: 6116 out of 25000 queries used.
53 Correct 7 ms 8276 KB Correct: 6174 out of 25000 queries used.
54 Correct 5 ms 7892 KB Correct: 4888 out of 25000 queries used.
55 Correct 6 ms 8272 KB Correct: 6114 out of 25000 queries used.
56 Correct 6 ms 8244 KB Correct: 6461 out of 25000 queries used.
57 Correct 6 ms 8276 KB Correct: 6386 out of 25000 queries used.
58 Correct 6 ms 8276 KB Correct: 6536 out of 25000 queries used.
59 Correct 6 ms 8264 KB Correct: 6058 out of 25000 queries used.
60 Correct 5 ms 8148 KB Correct: 3609 out of 25000 queries used.
61 Correct 6 ms 8148 KB Correct: 5145 out of 25000 queries used.
62 Correct 7 ms 8020 KB Correct: 5195 out of 25000 queries used.
63 Correct 6 ms 8276 KB Correct: 5160 out of 25000 queries used.
64 Correct 6 ms 8148 KB Correct: 5015 out of 25000 queries used.
65 Correct 5 ms 7812 KB Correct: 2808 out of 25000 queries used.
66 Correct 6 ms 8276 KB Correct: 6113 out of 25000 queries used.
67 Correct 5 ms 8020 KB Correct: 3879 out of 25000 queries used.
68 Correct 7 ms 8256 KB Correct: 7437 out of 25000 queries used.
69 Correct 7 ms 8252 KB Correct: 7450 out of 25000 queries used.
70 Correct 6 ms 8276 KB Correct: 5115 out of 25000 queries used.