Submission #25639

# Submission time Handle Problem Language Result Execution time Memory
25639 2017-06-23T10:08:47 Z Extazy Adriatic (CEOI13_adriatic) C++14
25 / 100
2000 ms 198412 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 7000;
const int INF = (1e9) + 7;

pair < int, int > a[N];

int get_dist(pair < int, int > a, pair < int, int > b){
    return abs(a.first-b.first)+abs(a.second-b.second);
}

struct cmp {
    pair < int, int > d;
    cmp(){}
    cmp(pair < int, int > a) {
        d=a;
    }
    bool operator ()(const int &x, const int &y) const {
        return get_dist(a[x],d)<get_dist(a[y],d);
    }
};

int n;
vector < int > v[N];
bool in[N];
int dist[N][N];

void spfa(int start, int *dist) {
    int i,curr;
    queue < int > q;

    for(i=1;i<=n;i++) dist[i]=INF;

    memset(in,0,sizeof(in));
    dist[start]=0;
    q.push(start);
    in[start]=true;
    
    while(!q.empty()) {
        curr=q.front();
        in[curr]=false;
        q.pop();
        
        for(i=0;i<(int)(v[curr].size());i++) {
            int current_distance=dist[curr]+1;
            if(dist[v[curr][i]]>current_distance) {
                dist[v[curr][i]]=current_distance;
                if(!in[v[curr][i]]) {
                    in[v[curr][i]]=true;
                    q.push(v[curr][i]);
                }
            }
        }
    }
}

int main() {
    int i,j;

    scanf("%d", &n);
    for(i=1;i<=n;i++) {
        scanf("%d %d", &a[i].first, &a[i].second);
    }
    
    for(i=1;i<=n;i++) {
        for(j=i+1;j<=n;j++) {
            if((a[i].first>a[j].first && a[i].second>a[j].second) || (a[i].first<a[j].first && a[i].second<a[j].second)) {
                v[i].push_back(j);
                v[j].push_back(i);
            }
        }
    }

    for(i=1;i<=n;i++) {
        sort(v[i].begin(),v[i].end(),cmp(a[i]));
    }

    for(i=1;i<=n;i++) {
        while(v[i].size()>200) v[i].pop_back();
        spfa(i,dist[i]);
        long long sum=0;
        for(j=1;j<=n;j++) {
            sum+=dist[i][j];
        }
        printf("%lld\n", sum);
    }

    return 0;
}

Compilation message

adriatic.cpp: In function 'int main()':
adriatic.cpp:62:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
adriatic.cpp:64:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a[i].first, &a[i].second);
                                                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 193656 KB Output is correct
2 Correct 0 ms 193656 KB Output is correct
3 Correct 0 ms 193656 KB Output is correct
4 Correct 0 ms 193656 KB Output is correct
5 Correct 0 ms 193656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 446 ms 194316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2000 ms 198412 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 193656 KB Execution killed because of forbidden syscall futex (202)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 193656 KB Execution killed because of forbidden syscall futex (202)
2 Halted 0 ms 0 KB -