Submission #961480

# Submission time Handle Problem Language Result Execution time Memory
961480 2024-04-12T07:24:02 Z vjudge1 City Mapping (NOI18_citymapping) C++17
57 / 100
48 ms 13796 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"

const int maxn = 1e3 + 100;
const ll INF = (ll)1e18 + 100;
const int inf = 1e9 + 100;
const int MOD = 1e9 + 7;
const int maxl = 30;
const int P = 31;

long long get_distance(int X, int Y);

int n;
ll d[maxn][maxn];
vector<pii> ans;

void calc(vector<int> v){
	sort(v.begin(), v.end(), [](int i, int j){
		return d[1][i] < d[1][j];
	});
	vector<vector<int>> to;
	for(int i: v){
		if(i == v[0]) continue;
		bool ok = 1;
		for(auto &s: to){
			if(d[v[0]][s[0]] + d[s[0]][i] == d[v[0]][i]){
				s.push_back(i);
				ok = 0;
				break;
			}
		}
		if(ok) to.push_back({i});
	}
	for(auto &s: to){
		ans.push_back({v[0], s[0]});
		calc(s);
	}
}

void find_roads(int N, int Q, int A[], int B[], int W[]){
	n = N;
	if(Q == 5e5){
		for(int i = 1; i <= n; i++){
			for(int j = i + 1; j <= n; j++){
				d[i][j] = d[j][i] = get_distance(i, j);
			}
		}
		vector<int> v;
		for(int i = 1; i <= n; i++){
			v.push_back(i);
		}
		calc(v);
		for(int i = 0; i < n-1; i++){
			A[i] = ans[i].first;
			B[i] = ans[i].second;
			W[i] = d[A[i]][B[i]];
		}
	} else{
		vector<int> v;
		vector<pii> l, r;
		for(int i = 2; i <= n; i++){
			v.push_back(i);
			d[1][i] = get_distance(1, i);
		}
		sort(v.begin(), v.end(), [](int i, int j){
			return d[1][i] < d[1][j];
		});
		for(int i: v){
			if(i == v[0]){
				l.push_back({i, d[1][i]});
				continue;
			}
			if(get_distance(v[0], i) + d[1][v[0]] == d[1][i]){
				l.push_back({i, d[1][i]});
			} else{
				r.push_back({i, d[1][i]});
			}
		}
		for(int i = 0; i < l.size(); i++){
			int j = 1, x = 0;
			if(i) j = l[i-1].first, x = l[i-1].second;
			A[i] = j; B[i] = l[i].first;
			W[i] = l[i].second - x;
		}
		for(int i = 0; i < r.size(); i++){
			int j = 1, x = 0;
			if(i) j = r[i-1].first, x = r[i-1].second;
			A[i+l.size()] = j; B[i+l.size()] = r[i].first;
			W[i+l.size()] = r[i].second - x;
		}

	}
}

Compilation message

citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:83:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   for(int i = 0; i < l.size(); i++){
      |                  ~~^~~~~~~~~~
citymapping.cpp:89:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |   for(int i = 0; i < r.size(); i++){
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 48 ms 10628 KB Correct: 498501 out of 500000 queries used.
2 Correct 37 ms 11092 KB Correct: 499500 out of 500000 queries used.
3 Correct 32 ms 9048 KB Correct: 492528 out of 500000 queries used.
4 Correct 23 ms 9184 KB Correct: 494515 out of 500000 queries used.
5 Correct 37 ms 9144 KB Correct: 498501 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 48 ms 10628 KB Correct: 498501 out of 500000 queries used.
2 Correct 37 ms 11092 KB Correct: 499500 out of 500000 queries used.
3 Correct 32 ms 9048 KB Correct: 492528 out of 500000 queries used.
4 Correct 23 ms 9184 KB Correct: 494515 out of 500000 queries used.
5 Correct 37 ms 9144 KB Correct: 498501 out of 500000 queries used.
6 Correct 41 ms 13796 KB Correct: 495510 out of 500000 queries used.
7 Correct 39 ms 11104 KB Correct: 497503 out of 500000 queries used.
8 Correct 28 ms 9308 KB Correct: 497503 out of 500000 queries used.
9 Correct 23 ms 9052 KB Correct: 495510 out of 500000 queries used.
10 Correct 37 ms 9296 KB Correct: 496506 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Correct: 1979 out of 12000 queries used.
2 Correct 1 ms 600 KB Correct: 1983 out of 12000 queries used.
3 Correct 1 ms 604 KB Correct: 1997 out of 12000 queries used.
4 Correct 1 ms 600 KB Correct: 1983 out of 12000 queries used.
5 Correct 1 ms 604 KB Correct: 1979 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Correct: 1979 out of 12000 queries used.
2 Correct 1 ms 600 KB Correct: 1983 out of 12000 queries used.
3 Correct 1 ms 604 KB Correct: 1997 out of 12000 queries used.
4 Correct 1 ms 600 KB Correct: 1983 out of 12000 queries used.
5 Correct 1 ms 604 KB Correct: 1979 out of 12000 queries used.
6 Correct 1 ms 600 KB Correct: 1993 out of 12000 queries used.
7 Correct 1 ms 604 KB Correct: 1989 out of 12000 queries used.
8 Correct 1 ms 604 KB Correct: 1997 out of 12000 queries used.
9 Correct 1 ms 608 KB Correct: 1991 out of 12000 queries used.
10 Correct 1 ms 608 KB Correct: 1985 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 48 ms 10628 KB Correct: 498501 out of 500000 queries used.
2 Correct 37 ms 11092 KB Correct: 499500 out of 500000 queries used.
3 Correct 32 ms 9048 KB Correct: 492528 out of 500000 queries used.
4 Correct 23 ms 9184 KB Correct: 494515 out of 500000 queries used.
5 Correct 37 ms 9144 KB Correct: 498501 out of 500000 queries used.
6 Correct 41 ms 13796 KB Correct: 495510 out of 500000 queries used.
7 Correct 39 ms 11104 KB Correct: 497503 out of 500000 queries used.
8 Correct 28 ms 9308 KB Correct: 497503 out of 500000 queries used.
9 Correct 23 ms 9052 KB Correct: 495510 out of 500000 queries used.
10 Correct 37 ms 9296 KB Correct: 496506 out of 500000 queries used.
11 Correct 1 ms 604 KB Correct: 1979 out of 12000 queries used.
12 Correct 1 ms 600 KB Correct: 1983 out of 12000 queries used.
13 Correct 1 ms 604 KB Correct: 1997 out of 12000 queries used.
14 Correct 1 ms 600 KB Correct: 1983 out of 12000 queries used.
15 Correct 1 ms 604 KB Correct: 1979 out of 12000 queries used.
16 Correct 1 ms 600 KB Correct: 1993 out of 12000 queries used.
17 Correct 1 ms 604 KB Correct: 1989 out of 12000 queries used.
18 Correct 1 ms 604 KB Correct: 1997 out of 12000 queries used.
19 Correct 1 ms 608 KB Correct: 1991 out of 12000 queries used.
20 Correct 1 ms 608 KB Correct: 1985 out of 12000 queries used.
21 Correct 2 ms 604 KB Correct: 1989 out of 25000 queries used.
22 Incorrect 1 ms 600 KB Reported list of edges differ from actual.
23 Halted 0 ms 0 KB -