Submission #2115243
Source Code Expand
#include<iostream> #include<algorithm> #include<vector> using namespace std; typedef pair<int, int> P; typedef long long int ll; static const int MAX_N = 100000; static const ll INF = 1LL << 60; struct edge{int to; ll cost;}; int N; int x[MAX_N], y[MAX_N]; P s1[MAX_N], s2[MAX_N]; vector<edge> G[MAX_N]; ll mincost[MAX_N]; bool used[MAX_N]; ll prim(){ fill(mincost, mincost + N, INF); fill(used, used + N, false); mincost[0] = 0; ll res = 0; for(;;){ int v = -1; for(int u = 0; u < N; u++){ if(!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u; } if(v == -1) break; used[v] = true; res += mincost[v]; for(int i = 0; i < G[v].size(); i++){ mincost[G[v][i].to] = min(mincost[G[v][i].to], G[v][i].cost); } } return res; } int main(){ cin >> N; for(int i = 0; i < N; i++){ cin >> x[i] >> y[i]; } for(int i = 0; i < N; i++){ s1[i].first = x[i]; s1[i].second = i; s2[i].first = y[i]; s2[i].second = i; } sort(s1, s1 + N); sort(s2, s2 + N); for(int i = 0; i < N - 1; i++){ G[s1[i].second].push_back((edge){s1[i + 1].second, abs(s1[i].first - s1[i + 1].first)}); G[s1[i + 1].second].push_back((edge){s1[i].second, abs(s1[i].first - s1[i + 1].first)}); G[s2[i].second].push_back((edge){s2[i + 1].second, abs(s2[i].first - s2[i + 1].first)}); G[s2[i + 1].second].push_back((edge){s2[i].second, abs(s2[i].first - s2[i + 1].first)}); } cout << prim() << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Built? |
User | utsumi |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1484 Byte |
Status | TLE |
Exec Time | 2104 ms |
Memory | 16384 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 500 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, s1.txt, s2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | TLE | 2104 ms | 14336 KB |
02.txt | TLE | 2104 ms | 14336 KB |
03.txt | TLE | 2104 ms | 14336 KB |
04.txt | TLE | 2104 ms | 14336 KB |
05.txt | TLE | 2104 ms | 16384 KB |
06.txt | TLE | 2104 ms | 14336 KB |
07.txt | TLE | 2104 ms | 14336 KB |
08.txt | TLE | 2104 ms | 14336 KB |
09.txt | TLE | 2104 ms | 14336 KB |
10.txt | TLE | 2104 ms | 14336 KB |
11.txt | TLE | 2104 ms | 14336 KB |
12.txt | TLE | 2104 ms | 14336 KB |
13.txt | TLE | 2104 ms | 14336 KB |
14.txt | TLE | 2104 ms | 14336 KB |
15.txt | TLE | 2104 ms | 13568 KB |
16.txt | TLE | 2104 ms | 13696 KB |
17.txt | TLE | 2104 ms | 13696 KB |
18.txt | TLE | 2104 ms | 15616 KB |
19.txt | TLE | 2104 ms | 13568 KB |
20.txt | TLE | 2104 ms | 13568 KB |
21.txt | TLE | 2104 ms | 13568 KB |
22.txt | TLE | 2104 ms | 15616 KB |
23.txt | TLE | 2104 ms | 13568 KB |
24.txt | TLE | 2104 ms | 14336 KB |
25.txt | AC | 2 ms | 3456 KB |
26.txt | AC | 2 ms | 3456 KB |
s1.txt | AC | 2 ms | 3456 KB |
s2.txt | AC | 2 ms | 3456 KB |