답안 #1065134

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065134 2024-08-19T00:15:13 Z Luvidi City Mapping (NOI18_citymapping) C++17
57 / 100
3 ms 1372 KB
#include <bits/stdc++.h>
#include "citymapping.h"
using namespace std;

#define ll long long
#define pb push_back
#define fs first
#define sc second
#define pll pair<ll,ll>

int *a,*b,*w,n,cnt;
vector<int> ch[1001];
pll r[1001];

void solve(int v){
	if(ch[v].empty())return;
	ll dist[n+1];
	pll fr;
	dist[v]=0;
	for(int i:ch[v]){
		dist[i]=get_distance(i,v);
		fr=max(fr,{dist[i],i});
	}
	int x=fr.sc;
	ll dist2[n+1];
	vector<pll> pt;
	r[v]={1e18,1e18};
	for(int i:ch[v]){
		dist2[i]=get_distance(i,x);
		ll d=(dist[x]+dist[i]-dist2[i])/2,d2=(dist[i]+dist2[i]-dist[x])/2;
		if(!d2){
			r[i]={1e18,1e18};
			pt.pb({dist[i],i});
		}
	}
	pt.pb({0,v});
	sort(pt.begin(),pt.end());
	for(int i=1;i<pt.size();i++){
		a[cnt]=pt[i-1].sc;
		b[cnt]=pt[i].sc;
		w[cnt]=dist[b[cnt]]-dist[a[cnt]];
		cnt++;
	}

	for(int i:ch[v])if(i!=x){
		ll d=(dist[x]+dist[i]-dist2[i])/2,d2=(dist[i]+dist2[i]-dist[x])/2;
		if(!d2)continue;
		for(auto[xx,j]:pt){
			if(dist[j]==d){
				r[j]=min(r[j],{dist[i],i});
			}
		}
	}

	for(int i:ch[v])if(i!=x){
		ll d=(dist[x]+dist[i]-dist2[i])/2,d2=(dist[i]+dist2[i]-dist[x])/2;
		if(!d2)continue;
		for(auto[xx,j]:pt){
			if(dist[j]==d){
				int k=r[j].sc;
				if(k!=i)ch[k].pb(i);
			}
		}
	}
	for(int i=0;i<pt.size();i++){
		int j=pt[i].sc;
		if(r[j].sc<=n){
			a[cnt]=j;
			b[cnt]=r[j].sc;
			w[cnt]=dist[r[j].sc]-dist[j];
			cnt++;
			solve(r[j].sc);
		}
	}	
}

void find_roads(int N, int Q, int A[], int B[], int W[]) {
	a=A;
	b=B;
	w=W;
	n=N;
	ll dist[n+1];
	pll fr={0,1};
	for(int i=1;i<=n;i++){
		dist[i]=get_distance(1,i);
		fr=max(fr,{dist[i],i});
	}
	int x=fr.sc;
	for(int i=1;i<=n;i++)if(i!=x)ch[x].pb(i);
	solve(x);
}

Compilation message

citymapping.cpp: In function 'void solve(int)':
citymapping.cpp:30:6: warning: unused variable 'd' [-Wunused-variable]
   30 |   ll d=(dist[x]+dist[i]-dist2[i])/2,d2=(dist[i]+dist2[i]-dist[x])/2;
      |      ^
citymapping.cpp:38:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for(int i=1;i<pt.size();i++){
      |              ~^~~~~~~~~~
citymapping.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i=0;i<pt.size();i++){
      |              ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Correct: 2995 out of 500000 queries used.
2 Correct 1 ms 604 KB Correct: 2998 out of 500000 queries used.
3 Correct 1 ms 604 KB Correct: 7475 out of 500000 queries used.
4 Correct 1 ms 604 KB Correct: 8951 out of 500000 queries used.
5 Correct 2 ms 1116 KB Correct: 20177 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Correct: 2995 out of 500000 queries used.
2 Correct 1 ms 604 KB Correct: 2998 out of 500000 queries used.
3 Correct 1 ms 604 KB Correct: 7475 out of 500000 queries used.
4 Correct 1 ms 604 KB Correct: 8951 out of 500000 queries used.
5 Correct 2 ms 1116 KB Correct: 20177 out of 500000 queries used.
6 Correct 1 ms 600 KB Correct: 2986 out of 500000 queries used.
7 Correct 3 ms 1372 KB Correct: 28124 out of 500000 queries used.
8 Correct 2 ms 764 KB Correct: 7444 out of 500000 queries used.
9 Correct 2 ms 812 KB Correct: 9362 out of 500000 queries used.
10 Correct 2 ms 600 KB Correct: 8233 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Correct: 2971 out of 12000 queries used.
2 Correct 1 ms 544 KB Correct: 2977 out of 12000 queries used.
3 Correct 1 ms 604 KB Correct: 2998 out of 12000 queries used.
4 Correct 1 ms 604 KB Correct: 2977 out of 12000 queries used.
5 Correct 1 ms 680 KB Correct: 2971 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Correct: 2971 out of 12000 queries used.
2 Correct 1 ms 544 KB Correct: 2977 out of 12000 queries used.
3 Correct 1 ms 604 KB Correct: 2998 out of 12000 queries used.
4 Correct 1 ms 604 KB Correct: 2977 out of 12000 queries used.
5 Correct 1 ms 680 KB Correct: 2971 out of 12000 queries used.
6 Correct 1 ms 604 KB Correct: 2992 out of 12000 queries used.
7 Correct 1 ms 604 KB Correct: 2986 out of 12000 queries used.
8 Correct 1 ms 604 KB Correct: 2998 out of 12000 queries used.
9 Correct 1 ms 664 KB Correct: 2989 out of 12000 queries used.
10 Correct 1 ms 652 KB Correct: 2980 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Correct: 2995 out of 500000 queries used.
2 Correct 1 ms 604 KB Correct: 2998 out of 500000 queries used.
3 Correct 1 ms 604 KB Correct: 7475 out of 500000 queries used.
4 Correct 1 ms 604 KB Correct: 8951 out of 500000 queries used.
5 Correct 2 ms 1116 KB Correct: 20177 out of 500000 queries used.
6 Correct 1 ms 600 KB Correct: 2986 out of 500000 queries used.
7 Correct 3 ms 1372 KB Correct: 28124 out of 500000 queries used.
8 Correct 2 ms 764 KB Correct: 7444 out of 500000 queries used.
9 Correct 2 ms 812 KB Correct: 9362 out of 500000 queries used.
10 Correct 2 ms 600 KB Correct: 8233 out of 500000 queries used.
11 Correct 2 ms 604 KB Correct: 2971 out of 12000 queries used.
12 Correct 1 ms 544 KB Correct: 2977 out of 12000 queries used.
13 Correct 1 ms 604 KB Correct: 2998 out of 12000 queries used.
14 Correct 1 ms 604 KB Correct: 2977 out of 12000 queries used.
15 Correct 1 ms 680 KB Correct: 2971 out of 12000 queries used.
16 Correct 1 ms 604 KB Correct: 2992 out of 12000 queries used.
17 Correct 1 ms 604 KB Correct: 2986 out of 12000 queries used.
18 Correct 1 ms 604 KB Correct: 2998 out of 12000 queries used.
19 Correct 1 ms 664 KB Correct: 2989 out of 12000 queries used.
20 Correct 1 ms 652 KB Correct: 2980 out of 12000 queries used.
21 Correct 2 ms 724 KB Correct: 2986 out of 25000 queries used.
22 Correct 1 ms 860 KB Correct: 7757 out of 25000 queries used.
23 Correct 1 ms 764 KB Correct: 3071 out of 25000 queries used.
24 Correct 1 ms 604 KB Correct: 5686 out of 25000 queries used.
25 Correct 1 ms 604 KB Correct: 7536 out of 25000 queries used.
26 Correct 1 ms 604 KB Correct: 7053 out of 25000 queries used.
27 Correct 1 ms 604 KB Correct: 7338 out of 25000 queries used.
28 Correct 2 ms 604 KB Correct: 7576 out of 25000 queries used.
29 Correct 2 ms 816 KB Correct: 8094 out of 25000 queries used.
30 Correct 2 ms 604 KB Correct: 8534 out of 25000 queries used.
31 Correct 2 ms 604 KB Correct: 8933 out of 25000 queries used.
32 Correct 1 ms 604 KB Correct: 2983 out of 25000 queries used.
33 Correct 1 ms 604 KB Correct: 8884 out of 25000 queries used.
34 Correct 1 ms 604 KB Correct: 8933 out of 25000 queries used.
35 Correct 2 ms 604 KB Correct: 8902 out of 25000 queries used.
36 Correct 2 ms 740 KB Correct: 8870 out of 25000 queries used.
37 Correct 1 ms 604 KB Correct: 8892 out of 25000 queries used.
38 Correct 1 ms 604 KB Correct: 8951 out of 25000 queries used.
39 Correct 2 ms 856 KB Correct: 8883 out of 25000 queries used.
40 Correct 1 ms 832 KB Correct: 8899 out of 25000 queries used.
41 Correct 1 ms 604 KB Correct: 8895 out of 25000 queries used.
42 Correct 1 ms 604 KB Correct: 8921 out of 25000 queries used.
43 Correct 1 ms 604 KB Correct: 2992 out of 25000 queries used.
44 Correct 1 ms 604 KB Correct: 8795 out of 25000 queries used.
45 Correct 1 ms 604 KB Correct: 8857 out of 25000 queries used.
46 Correct 1 ms 568 KB Correct: 8793 out of 25000 queries used.
47 Correct 2 ms 604 KB Correct: 8885 out of 25000 queries used.
48 Correct 1 ms 604 KB Correct: 8958 out of 25000 queries used.
49 Correct 1 ms 604 KB Correct: 8959 out of 25000 queries used.
50 Correct 1 ms 764 KB Correct: 8920 out of 25000 queries used.
51 Correct 1 ms 604 KB Correct: 8958 out of 25000 queries used.
52 Correct 1 ms 604 KB Correct: 8883 out of 25000 queries used.
53 Correct 1 ms 604 KB Correct: 9458 out of 25000 queries used.
54 Incorrect 3 ms 860 KB Too many calls to get_distance().
55 Halted 0 ms 0 KB -