Submission #1373613


Source Code Expand

Copy
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
struct Union_Find{
    int d[SIZE],num[SIZE];
    void init(int n){
        REP(i,n)d[i]=i,num[i]=1;
    }
    int find(int x){
        return (x!=d[x])?(d[x]=find(d[x])):x;
    }
    bool uu(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y)return 0;
        if(num[x]>num[y])swap(x,y);
        num[y]+=num[x];
        d[x]=y;
        return 1;
    }
}U;
int main(){
    VPII X,Y;
    vector<pair<int,PII> >ppp;
    DRI(N);
    U.init(N);
    REP(i,N){
        DRII(x,y);
        X.PB(MP(x,i));
        Y.PB(MP(y,i));
    }
    sort(ALL(X));
    sort(ALL(Y));
    REPP(i,1,N){
        ppp.PB(MP(X[i].F-X[i-1].F,MP(X[i].S,X[i-1].S)));
        ppp.PB(MP(Y[i].F-Y[i-1].F,MP(Y[i].S,Y[i-1].S)));
    }
    sort(ALL(ppp));
    int an=0;
    REP(i,SZ(ppp)){
        if(U.uu(ppp[i].S.F,ppp[i].S.S))an+=ppp[i].F;
    }
    cout<<an<<endl;
    return 0;
}

Submission Info

Submission Time
Task D - Built?
User dreamoon
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2006 Byte
Status
Exec Time 64 ms
Memory 11624 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:52:11: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     DRI(N);
           ^
./Main.cpp:55:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         DRII(x,y);
                  ^

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt
All 500 / 500 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 63 ms 10088 KB
02.txt 63 ms 11624 KB
03.txt 64 ms 10088 KB
04.txt 63 ms 11368 KB
05.txt 63 ms 10088 KB
06.txt 63 ms 10088 KB
07.txt 63 ms 11624 KB
08.txt 63 ms 10600 KB
09.txt 63 ms 10088 KB
10.txt 63 ms 10728 KB
11.txt 63 ms 10088 KB
12.txt 63 ms 10088 KB
13.txt 47 ms 10088 KB
14.txt 47 ms 11496 KB
15.txt 57 ms 11496 KB
16.txt 62 ms 10088 KB
17.txt 64 ms 10088 KB
18.txt 60 ms 10984 KB
19.txt 57 ms 11496 KB
20.txt 61 ms 10088 KB
21.txt 59 ms 10088 KB
22.txt 61 ms 10088 KB
23.txt 33 ms 11368 KB
24.txt 57 ms 10088 KB
25.txt 2 ms 2304 KB
26.txt 2 ms 2304 KB
s1.txt 2 ms 2304 KB
s2.txt 2 ms 2304 KB