Submission #592711

# Submission time Handle Problem Language Result Execution time Memory
592711 2022-07-09T13:45:47 Z Blagojce City Mapping (NOI18_citymapping) C++11
32 / 100
7 ms 8276 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, 1, (int)diam.size()){
		auto d = diam[i];
		for(auto s : sub[i]){
			dist[d][s] = 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 6 ms 7892 KB Correct: 2218 out of 500000 queries used.
2 Incorrect 6 ms 7636 KB Reported list of edges differ from actual.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7892 KB Correct: 2218 out of 500000 queries used.
2 Incorrect 6 ms 7636 KB Reported list of edges differ from actual.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7408 KB Correct: 3023 out of 12000 queries used.
2 Correct 6 ms 8016 KB Correct: 2967 out of 12000 queries used.
3 Correct 5 ms 8020 KB Correct: 2918 out of 12000 queries used.
4 Correct 7 ms 8068 KB Correct: 2047 out of 12000 queries used.
5 Correct 5 ms 7744 KB Correct: 2148 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7408 KB Correct: 3023 out of 12000 queries used.
2 Correct 6 ms 8016 KB Correct: 2967 out of 12000 queries used.
3 Correct 5 ms 8020 KB Correct: 2918 out of 12000 queries used.
4 Correct 7 ms 8068 KB Correct: 2047 out of 12000 queries used.
5 Correct 5 ms 7744 KB Correct: 2148 out of 12000 queries used.
6 Correct 5 ms 7892 KB Correct: 2874 out of 12000 queries used.
7 Correct 5 ms 6996 KB Correct: 2422 out of 12000 queries used.
8 Correct 5 ms 7636 KB Correct: 2674 out of 12000 queries used.
9 Correct 5 ms 8276 KB Correct: 2371 out of 12000 queries used.
10 Correct 5 ms 8016 KB Correct: 2188 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7892 KB Correct: 2218 out of 500000 queries used.
2 Incorrect 6 ms 7636 KB Reported list of edges differ from actual.
3 Halted 0 ms 0 KB -