Submission #592721

# Submission time Handle Problem Language Result Execution time Memory
592721 2022-07-09T14:00:36 Z Blagojce City Mapping (NOI18_citymapping) C++11
92 / 100
8 ms 8332 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 6672 KB Correct: 2298 out of 500000 queries used.
2 Correct 5 ms 8052 KB Correct: 2526 out of 500000 queries used.
3 Correct 6 ms 8276 KB Correct: 5223 out of 500000 queries used.
4 Correct 5 ms 8276 KB Correct: 6124 out of 500000 queries used.
5 Correct 5 ms 8148 KB Correct: 5668 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 5 ms 6672 KB Correct: 2298 out of 500000 queries used.
2 Correct 5 ms 8052 KB Correct: 2526 out of 500000 queries used.
3 Correct 6 ms 8276 KB Correct: 5223 out of 500000 queries used.
4 Correct 5 ms 8276 KB Correct: 6124 out of 500000 queries used.
5 Correct 5 ms 8148 KB Correct: 5668 out of 500000 queries used.
6 Correct 4 ms 7172 KB Correct: 2413 out of 500000 queries used.
7 Correct 6 ms 8180 KB Correct: 5749 out of 500000 queries used.
8 Correct 6 ms 8284 KB Correct: 5453 out of 500000 queries used.
9 Correct 6 ms 8276 KB Correct: 6451 out of 500000 queries used.
10 Correct 7 ms 8276 KB Correct: 5100 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7636 KB Correct: 2728 out of 12000 queries used.
2 Correct 5 ms 7764 KB Correct: 2087 out of 12000 queries used.
3 Correct 4 ms 6484 KB Correct: 2006 out of 12000 queries used.
4 Correct 5 ms 7564 KB Correct: 2364 out of 12000 queries used.
5 Correct 5 ms 7636 KB Correct: 2264 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7636 KB Correct: 2728 out of 12000 queries used.
2 Correct 5 ms 7764 KB Correct: 2087 out of 12000 queries used.
3 Correct 4 ms 6484 KB Correct: 2006 out of 12000 queries used.
4 Correct 5 ms 7564 KB Correct: 2364 out of 12000 queries used.
5 Correct 5 ms 7636 KB Correct: 2264 out of 12000 queries used.
6 Correct 5 ms 7764 KB Correct: 2392 out of 12000 queries used.
7 Correct 6 ms 7704 KB Correct: 2264 out of 12000 queries used.
8 Correct 5 ms 7168 KB Correct: 2575 out of 12000 queries used.
9 Correct 4 ms 6868 KB Correct: 2343 out of 12000 queries used.
10 Correct 4 ms 6996 KB Correct: 2347 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 5 ms 6672 KB Correct: 2298 out of 500000 queries used.
2 Correct 5 ms 8052 KB Correct: 2526 out of 500000 queries used.
3 Correct 6 ms 8276 KB Correct: 5223 out of 500000 queries used.
4 Correct 5 ms 8276 KB Correct: 6124 out of 500000 queries used.
5 Correct 5 ms 8148 KB Correct: 5668 out of 500000 queries used.
6 Correct 4 ms 7172 KB Correct: 2413 out of 500000 queries used.
7 Correct 6 ms 8180 KB Correct: 5749 out of 500000 queries used.
8 Correct 6 ms 8284 KB Correct: 5453 out of 500000 queries used.
9 Correct 6 ms 8276 KB Correct: 6451 out of 500000 queries used.
10 Correct 7 ms 8276 KB Correct: 5100 out of 500000 queries used.
11 Correct 5 ms 7636 KB Correct: 2728 out of 12000 queries used.
12 Correct 5 ms 7764 KB Correct: 2087 out of 12000 queries used.
13 Correct 4 ms 6484 KB Correct: 2006 out of 12000 queries used.
14 Correct 5 ms 7564 KB Correct: 2364 out of 12000 queries used.
15 Correct 5 ms 7636 KB Correct: 2264 out of 12000 queries used.
16 Correct 5 ms 7764 KB Correct: 2392 out of 12000 queries used.
17 Correct 6 ms 7704 KB Correct: 2264 out of 12000 queries used.
18 Correct 5 ms 7168 KB Correct: 2575 out of 12000 queries used.
19 Correct 4 ms 6868 KB Correct: 2343 out of 12000 queries used.
20 Correct 4 ms 6996 KB Correct: 2347 out of 12000 queries used.
21 Correct 6 ms 7764 KB Correct: 2579 out of 25000 queries used.
22 Correct 6 ms 7836 KB Correct: 4035 out of 25000 queries used.
23 Correct 5 ms 7764 KB Correct: 3019 out of 25000 queries used.
24 Correct 5 ms 8020 KB Correct: 3895 out of 25000 queries used.
25 Correct 8 ms 8276 KB Correct: 6032 out of 25000 queries used.
26 Correct 5 ms 8148 KB Correct: 5608 out of 25000 queries used.
27 Correct 6 ms 8276 KB Correct: 5584 out of 25000 queries used.
28 Correct 5 ms 8276 KB Correct: 5923 out of 25000 queries used.
29 Correct 6 ms 8312 KB Correct: 5562 out of 25000 queries used.
30 Correct 5 ms 8276 KB Correct: 5813 out of 25000 queries used.
31 Correct 6 ms 8332 KB Correct: 6161 out of 25000 queries used.
32 Correct 6 ms 7124 KB Correct: 2592 out of 25000 queries used.
33 Correct 6 ms 8276 KB Correct: 6043 out of 25000 queries used.
34 Correct 6 ms 8276 KB Correct: 6117 out of 25000 queries used.
35 Correct 6 ms 8276 KB Correct: 6216 out of 25000 queries used.
36 Correct 6 ms 8276 KB Correct: 6090 out of 25000 queries used.
37 Correct 6 ms 8276 KB Correct: 6219 out of 25000 queries used.
38 Correct 6 ms 8276 KB Correct: 6077 out of 25000 queries used.
39 Correct 6 ms 8276 KB Correct: 6054 out of 25000 queries used.
40 Correct 7 ms 8276 KB Correct: 6132 out of 25000 queries used.
41 Correct 8 ms 8272 KB Correct: 6182 out of 25000 queries used.
42 Correct 6 ms 8256 KB Correct: 6174 out of 25000 queries used.
43 Correct 5 ms 8112 KB Correct: 2525 out of 25000 queries used.
44 Correct 5 ms 8152 KB Correct: 6211 out of 25000 queries used.
45 Correct 5 ms 8148 KB Correct: 6032 out of 25000 queries used.
46 Correct 6 ms 8148 KB Correct: 5945 out of 25000 queries used.
47 Correct 6 ms 8216 KB Correct: 6054 out of 25000 queries used.
48 Correct 6 ms 8276 KB Correct: 6089 out of 25000 queries used.
49 Correct 6 ms 8276 KB Correct: 6013 out of 25000 queries used.
50 Correct 7 ms 8212 KB Correct: 6096 out of 25000 queries used.
51 Correct 6 ms 8236 KB Correct: 6250 out of 25000 queries used.
52 Correct 8 ms 8256 KB Correct: 6221 out of 25000 queries used.
53 Correct 8 ms 8260 KB Correct: 6440 out of 25000 queries used.
54 Correct 6 ms 8160 KB Correct: 4185 out of 25000 queries used.
55 Correct 6 ms 8276 KB Correct: 6047 out of 25000 queries used.
56 Correct 7 ms 8276 KB Correct: 6012 out of 25000 queries used.
57 Correct 8 ms 8324 KB Correct: 6103 out of 25000 queries used.
58 Correct 6 ms 8276 KB Correct: 5986 out of 25000 queries used.
59 Correct 6 ms 8276 KB Correct: 5956 out of 25000 queries used.
60 Correct 6 ms 8148 KB Correct: 7416 out of 25000 queries used.
61 Correct 5 ms 8020 KB Correct: 4601 out of 25000 queries used.
62 Correct 6 ms 8148 KB Correct: 4214 out of 25000 queries used.
63 Correct 5 ms 8276 KB Correct: 3950 out of 25000 queries used.
64 Correct 5 ms 8148 KB Correct: 4834 out of 25000 queries used.
65 Correct 5 ms 7764 KB Correct: 3442 out of 25000 queries used.
66 Correct 6 ms 8196 KB Correct: 6785 out of 25000 queries used.
67 Correct 6 ms 7892 KB Correct: 4600 out of 25000 queries used.
68 Correct 6 ms 8148 KB Correct: 3655 out of 25000 queries used.
69 Correct 6 ms 7852 KB Correct: 2189 out of 25000 queries used.
70 Correct 6 ms 8276 KB Correct: 5124 out of 25000 queries used.