답안 #25632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25632 2017-06-23T09:20:13 Z Extazy 섬 항해 (CEOI13_adriatic) C++14
25 / 100
2000 ms 200540 KB
#include <bits/stdc++.h>

using namespace std;

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

int n;
pair < int, int > a[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++) {
        random_shuffle(v[i].begin(),v[i].end());
    }

    for(i=1;i<=n;i++) {
        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:46:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
adriatic.cpp:48: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);
                                                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 193656 KB Output is correct
2 Correct 3 ms 193656 KB Output is correct
3 Correct 0 ms 193656 KB Output is correct
4 Correct 3 ms 193656 KB Output is correct
5 Correct 0 ms 193656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 446 ms 194316 KB Output is correct
2 Execution timed out 2000 ms 200540 KB Execution timed out
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2000 ms 198412 KB Execution timed out
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1143 ms 196824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 276 ms 194976 KB Output isn't correct
2 Halted 0 ms 0 KB -