답안 #93619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93619 2019-01-10T11:19:07 Z admin City Mapping (NOI18_citymapping) C++17
95.71 / 100
30 ms 12408 KB
#include "citymapping.h"
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll LINF = 0x3f3f3f3f3f3f3f3f;
 
vector<pll> lis;
ll di[1010][1010];
vector<pll> ttis[1010];
int par[1010];
 
ll calc(int u, int v) {
    if (di[u][v]) return di[u][v];
    if (u==v) return 0;
    ll d = get_distance(u+1,v+1);
    di[u][v] = di[v][u] = d;
    return d;
}
 
int head, q;
int dir[1010][1010];
void add(int u, int v, int A[], int B[], int W[]) {
    A[q] = u;
    B[q] = v;
    W[q] = calc(head,v)-calc(head,u);
    par[v] = u;
    ttis[u].push_back(pll(W[q],v));
    int p = v;
    while(p!=head) {
        int pp = par[p];
        for (int i=0;i<ttis[pp].size();i++) if (ttis[pp][i].second==p) {
            dir[pp][v] = i;
            break;
        }
        p = pp;
    }
    q++;
}
 
int D[1010], E[1010];
void dfs(int here) {
    for (pll &tmp : ttis[here]) {
        dfs(tmp.second);
    }
    if (ttis[here].empty()) {
        D[here] = 0;
        E[here] = here;
        return;
    }
    if (ttis[here].size()==1) {
        D[here]=D[ttis[here][0].second];
        E[here]=E[ttis[here][0].second];
        return;
    }
    int t = (D[ttis[here][0].second]>D[ttis[here][1].second]?0:1);
    D[here]=max(D[ttis[here][t].second]-1,D[ttis[here][1-t].second])+1;
    E[here]=E[ttis[here][t].second];
}
 
void find_roads(int n, int Q, int A[], int B[], int W[]) {
    memset(par,-1,sizeof(par));
    int i, j;
    ll maxi = 0;
    for (i=1;i<n;i++) {
        if (maxi<calc(0,i)) {
            maxi=calc(0,i);
            head=i;
        }
    }
    //printf("\n%d\n",head);
    vector<pll> pis;
    for (i=0;i<n;i++) {
        //if (calc(head,i)+calc(0,i)==calc(0,head)) {
        //    pis.push_back(pll(calc(i,head),i));
        //}
        //else
        lis.push_back(pll(calc(i,head),i));
    }
    //sort(pis.begin(),pis.end());
    //for (j=1;j<pis.size();j++) {
    //    add(pis[j-1].second,pis[j].second);
    //}
    sort(lis.begin(),lis.end());
    add(lis[0].second,lis[1].second,A,B,W);
    for (j=2;j<lis.size();j++) {
        dfs(lis[1].second);
        int idx = lis[j].second;
        ll mini = LINF;
        int p = lis[1].second;
        while(!ttis[p].empty()) {
            ll d = (calc(head,idx)+calc(head,E[p])-calc(E[p],idx))/2;
            int v = E[p];
            while(calc(head,p)<d) {
                p = ttis[p][dir[p][v]].second;
            }
            if (ttis[p].size()<=1) break;
            p = ttis[p][1-dir[p][v]].second;
        }
        add(p,idx,A,B,W);
    }
  for(int i =0 ;i<n-1;i++)A[i]+=1,B[i]+=1;
}

Compilation message

citymapping.cpp: In function 'void add(int, int, int*, int*, int*)':
citymapping.cpp:36:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i=0;i<ttis[pp].size();i++) if (ttis[pp][i].second==p) {
                      ~^~~~~~~~~~~~~~~~
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:90:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (j=2;j<lis.size();j++) {
              ~^~~~~~~~~~~
citymapping.cpp:93:12: warning: unused variable 'mini' [-Wunused-variable]
         ll mini = LINF;
            ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 11640 KB Correct: 2989 out of 500000 queries used.
2 Correct 20 ms 10872 KB Correct: 3246 out of 500000 queries used.
3 Correct 17 ms 11256 KB Correct: 5394 out of 500000 queries used.
4 Correct 15 ms 10872 KB Correct: 6412 out of 500000 queries used.
5 Correct 20 ms 12152 KB Correct: 3851 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 11640 KB Correct: 2989 out of 500000 queries used.
2 Correct 20 ms 10872 KB Correct: 3246 out of 500000 queries used.
3 Correct 17 ms 11256 KB Correct: 5394 out of 500000 queries used.
4 Correct 15 ms 10872 KB Correct: 6412 out of 500000 queries used.
5 Correct 20 ms 12152 KB Correct: 3851 out of 500000 queries used.
6 Correct 27 ms 12024 KB Correct: 2980 out of 500000 queries used.
7 Correct 19 ms 10104 KB Correct: 2987 out of 500000 queries used.
8 Correct 14 ms 11256 KB Correct: 5344 out of 500000 queries used.
9 Correct 14 ms 10872 KB Correct: 6242 out of 500000 queries used.
10 Correct 18 ms 12116 KB Correct: 3905 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 11896 KB Correct: 2965 out of 12000 queries used.
2 Correct 26 ms 11832 KB Correct: 2971 out of 12000 queries used.
3 Correct 27 ms 11768 KB Correct: 2992 out of 12000 queries used.
4 Correct 25 ms 11924 KB Correct: 2971 out of 12000 queries used.
5 Correct 25 ms 11896 KB Correct: 2965 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 11896 KB Correct: 2965 out of 12000 queries used.
2 Correct 26 ms 11832 KB Correct: 2971 out of 12000 queries used.
3 Correct 27 ms 11768 KB Correct: 2992 out of 12000 queries used.
4 Correct 25 ms 11924 KB Correct: 2971 out of 12000 queries used.
5 Correct 25 ms 11896 KB Correct: 2965 out of 12000 queries used.
6 Correct 26 ms 12408 KB Correct: 2986 out of 12000 queries used.
7 Correct 25 ms 11640 KB Correct: 2980 out of 12000 queries used.
8 Correct 27 ms 11640 KB Correct: 2992 out of 12000 queries used.
9 Correct 30 ms 12252 KB Correct: 2983 out of 12000 queries used.
10 Correct 26 ms 11512 KB Correct: 2974 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 11640 KB Correct: 2989 out of 500000 queries used.
2 Correct 20 ms 10872 KB Correct: 3246 out of 500000 queries used.
3 Correct 17 ms 11256 KB Correct: 5394 out of 500000 queries used.
4 Correct 15 ms 10872 KB Correct: 6412 out of 500000 queries used.
5 Correct 20 ms 12152 KB Correct: 3851 out of 500000 queries used.
6 Correct 27 ms 12024 KB Correct: 2980 out of 500000 queries used.
7 Correct 19 ms 10104 KB Correct: 2987 out of 500000 queries used.
8 Correct 14 ms 11256 KB Correct: 5344 out of 500000 queries used.
9 Correct 14 ms 10872 KB Correct: 6242 out of 500000 queries used.
10 Correct 18 ms 12116 KB Correct: 3905 out of 500000 queries used.
11 Correct 25 ms 11896 KB Correct: 2965 out of 12000 queries used.
12 Correct 26 ms 11832 KB Correct: 2971 out of 12000 queries used.
13 Correct 27 ms 11768 KB Correct: 2992 out of 12000 queries used.
14 Correct 25 ms 11924 KB Correct: 2971 out of 12000 queries used.
15 Correct 25 ms 11896 KB Correct: 2965 out of 12000 queries used.
16 Correct 26 ms 12408 KB Correct: 2986 out of 12000 queries used.
17 Correct 25 ms 11640 KB Correct: 2980 out of 12000 queries used.
18 Correct 27 ms 11640 KB Correct: 2992 out of 12000 queries used.
19 Correct 30 ms 12252 KB Correct: 2983 out of 12000 queries used.
20 Correct 26 ms 11512 KB Correct: 2974 out of 12000 queries used.
21 Correct 26 ms 12408 KB Correct: 2980 out of 25000 queries used.
22 Correct 21 ms 10464 KB Correct: 3506 out of 25000 queries used.
23 Correct 22 ms 11256 KB Correct: 3507 out of 25000 queries used.
24 Correct 20 ms 9720 KB Correct: 3489 out of 25000 queries used.
25 Correct 17 ms 11256 KB Correct: 5281 out of 25000 queries used.
26 Correct 16 ms 11000 KB Correct: 5300 out of 25000 queries used.
27 Correct 17 ms 11256 KB Correct: 5147 out of 25000 queries used.
28 Correct 16 ms 11256 KB Correct: 5475 out of 25000 queries used.
29 Correct 16 ms 11388 KB Correct: 5394 out of 25000 queries used.
30 Correct 16 ms 11128 KB Correct: 5401 out of 25000 queries used.
31 Correct 16 ms 11000 KB Correct: 6074 out of 25000 queries used.
32 Correct 28 ms 11644 KB Correct: 2977 out of 25000 queries used.
33 Correct 16 ms 11128 KB Correct: 6493 out of 25000 queries used.
34 Correct 16 ms 11000 KB Correct: 6227 out of 25000 queries used.
35 Correct 16 ms 10872 KB Correct: 6339 out of 25000 queries used.
36 Correct 16 ms 10872 KB Correct: 6363 out of 25000 queries used.
37 Correct 17 ms 10872 KB Correct: 6399 out of 25000 queries used.
38 Correct 16 ms 10872 KB Correct: 6356 out of 25000 queries used.
39 Correct 16 ms 11000 KB Correct: 6282 out of 25000 queries used.
40 Correct 15 ms 11000 KB Correct: 6378 out of 25000 queries used.
41 Correct 15 ms 11000 KB Correct: 6108 out of 25000 queries used.
42 Correct 15 ms 10872 KB Correct: 6327 out of 25000 queries used.
43 Correct 27 ms 12404 KB Correct: 2986 out of 25000 queries used.
44 Correct 14 ms 10872 KB Correct: 6326 out of 25000 queries used.
45 Correct 14 ms 10872 KB Correct: 6149 out of 25000 queries used.
46 Correct 15 ms 11004 KB Correct: 6401 out of 25000 queries used.
47 Correct 14 ms 10872 KB Correct: 6396 out of 25000 queries used.
48 Correct 14 ms 10872 KB Correct: 6736 out of 25000 queries used.
49 Correct 15 ms 10872 KB Correct: 6479 out of 25000 queries used.
50 Correct 14 ms 10872 KB Correct: 6310 out of 25000 queries used.
51 Correct 14 ms 10872 KB Correct: 6252 out of 25000 queries used.
52 Correct 14 ms 11004 KB Correct: 6270 out of 25000 queries used.
53 Correct 15 ms 11000 KB Correct: 6408 out of 25000 queries used.
54 Correct 22 ms 10232 KB Correct: 3493 out of 25000 queries used.
55 Correct 14 ms 10872 KB Correct: 6406 out of 25000 queries used.
56 Correct 15 ms 11000 KB Correct: 5930 out of 25000 queries used.
57 Correct 16 ms 10872 KB Correct: 6230 out of 25000 queries used.
58 Correct 16 ms 10872 KB Correct: 6142 out of 25000 queries used.
59 Correct 16 ms 10744 KB Correct: 6651 out of 25000 queries used.
60 Correct 20 ms 11896 KB Correct: 3825 out of 25000 queries used.
61 Correct 19 ms 12152 KB Correct: 4561 out of 25000 queries used.
62 Correct 19 ms 12024 KB Correct: 3940 out of 25000 queries used.
63 Correct 20 ms 12152 KB Correct: 3848 out of 25000 queries used.
64 Correct 19 ms 11896 KB Correct: 3877 out of 25000 queries used.
65 Correct 20 ms 9852 KB Correct: 3459 out of 25000 queries used.
66 Correct 20 ms 12284 KB Correct: 4647 out of 25000 queries used.
67 Correct 21 ms 11044 KB Correct: 3501 out of 25000 queries used.
68 Correct 23 ms 11384 KB Correct: 3461 out of 25000 queries used.
69 Correct 22 ms 10744 KB Correct: 3012 out of 25000 queries used.
70 Correct 22 ms 11128 KB Correct: 3472 out of 25000 queries used.