답안 #93617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93617 2019-01-10T11:15:34 Z admin City Mapping (NOI18_citymapping) C++17
57 / 100
36 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]);
    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 28 ms 11640 KB Correct: 2989 out of 500000 queries used.
2 Correct 36 ms 11384 KB Correct: 131013 out of 500000 queries used.
3 Correct 17 ms 11256 KB Correct: 14046 out of 500000 queries used.
4 Correct 15 ms 10872 KB Correct: 8236 out of 500000 queries used.
5 Correct 21 ms 12380 KB Correct: 9963 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 11640 KB Correct: 2989 out of 500000 queries used.
2 Correct 36 ms 11384 KB Correct: 131013 out of 500000 queries used.
3 Correct 17 ms 11256 KB Correct: 14046 out of 500000 queries used.
4 Correct 15 ms 10872 KB Correct: 8236 out of 500000 queries used.
5 Correct 21 ms 12380 KB Correct: 9963 out of 500000 queries used.
6 Correct 28 ms 12024 KB Correct: 2980 out of 500000 queries used.
7 Correct 26 ms 11132 KB Correct: 45201 out of 500000 queries used.
8 Correct 15 ms 11384 KB Correct: 8278 out of 500000 queries used.
9 Correct 14 ms 10988 KB Correct: 8968 out of 500000 queries used.
10 Correct 18 ms 12280 KB Correct: 9127 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 11768 KB Correct: 2965 out of 12000 queries used.
2 Correct 25 ms 11640 KB Correct: 2971 out of 12000 queries used.
3 Correct 25 ms 11768 KB Correct: 2992 out of 12000 queries used.
4 Correct 25 ms 11836 KB Correct: 2971 out of 12000 queries used.
5 Correct 26 ms 11896 KB Correct: 2965 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 11768 KB Correct: 2965 out of 12000 queries used.
2 Correct 25 ms 11640 KB Correct: 2971 out of 12000 queries used.
3 Correct 25 ms 11768 KB Correct: 2992 out of 12000 queries used.
4 Correct 25 ms 11836 KB Correct: 2971 out of 12000 queries used.
5 Correct 26 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 30 ms 11640 KB Correct: 2980 out of 12000 queries used.
8 Correct 29 ms 11640 KB Correct: 2992 out of 12000 queries used.
9 Correct 31 ms 12280 KB Correct: 2983 out of 12000 queries used.
10 Correct 25 ms 11640 KB Correct: 2974 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 11640 KB Correct: 2989 out of 500000 queries used.
2 Correct 36 ms 11384 KB Correct: 131013 out of 500000 queries used.
3 Correct 17 ms 11256 KB Correct: 14046 out of 500000 queries used.
4 Correct 15 ms 10872 KB Correct: 8236 out of 500000 queries used.
5 Correct 21 ms 12380 KB Correct: 9963 out of 500000 queries used.
6 Correct 28 ms 12024 KB Correct: 2980 out of 500000 queries used.
7 Correct 26 ms 11132 KB Correct: 45201 out of 500000 queries used.
8 Correct 15 ms 11384 KB Correct: 8278 out of 500000 queries used.
9 Correct 14 ms 10988 KB Correct: 8968 out of 500000 queries used.
10 Correct 18 ms 12280 KB Correct: 9127 out of 500000 queries used.
11 Correct 24 ms 11768 KB Correct: 2965 out of 12000 queries used.
12 Correct 25 ms 11640 KB Correct: 2971 out of 12000 queries used.
13 Correct 25 ms 11768 KB Correct: 2992 out of 12000 queries used.
14 Correct 25 ms 11836 KB Correct: 2971 out of 12000 queries used.
15 Correct 26 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 30 ms 11640 KB Correct: 2980 out of 12000 queries used.
18 Correct 29 ms 11640 KB Correct: 2992 out of 12000 queries used.
19 Correct 31 ms 12280 KB Correct: 2983 out of 12000 queries used.
20 Correct 25 ms 11640 KB Correct: 2974 out of 12000 queries used.
21 Correct 30 ms 12408 KB Correct: 2980 out of 25000 queries used.
22 Incorrect 19 ms 10488 KB Too many calls to get_distance().
23 Halted 0 ms 0 KB -