# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
101495 | 2019-03-19T03:19:35 Z | cheeheng | 섬 항해 (CEOI13_adriatic) | C++14 | 222 ms | 60628 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; int R[250000]; int C[250000]; int dist[250000]; vector<int> AdjList[250005]; vector<int> AdjList2[250005]; ii EdgeList[250005]; int rank1[250005]; int p[250005]; void init(int N){ for(int i = 0; i < N; i ++){ rank1[i] = 0; p[i] = i; } } int findSet(int i){ return (p[i] == i) ? i : (p[i] = findSet(p[i])); } bool isSameSet(int i, int j){ return findSet(i) == findSet(j); } void unionSet(int i, int j){ if(!isSameSet(i, j)){ int x = findSet(i); int y = findSet(j); if(rank1[x] > rank1[y]){ p[y] = x; }else{ p[x] = y; if(rank1[x] == rank1[y]){rank1[y] ++;} } } } int main(){ int N; scanf("%d", &N); for(int i = 0; i < N; i ++){ scanf("%d%d", &R[i], &C[i]); } int cnt = 0; for(int i = 0; i < N; i ++){ for(int j = i+1; j < N; j ++){ if((R[i] < R[j] && C[i] < C[j]) || (R[i] > R[j] && C[i] > C[j])){ AdjList[i].push_back(j); AdjList[j].push_back(i); EdgeList[cnt ++] = ii(i, j); } } } random_shuffle(EdgeList, EdgeList+cnt); // prevent worst-case time complexity init(N); int taken = 0; for(int i = 0; i < cnt && taken < max(10000,2*N); i ++){ int u = EdgeList[i].first; int v = EdgeList[i].second; if(!isSameSet(u, v) || taken >= N-1){ unionSet(u, v); AdjList2[u].push_back(v); AdjList2[v].push_back(u); taken ++; } } for(int i = 0; i < N; i ++){ long long ans = 0; memset(dist, -1, sizeof(dist)); queue<int> q; q.push(i); dist[i] = 0; while(!q.empty()){ int u = q.front(); q.pop(); for(int v: AdjList2[u]){ if(dist[v] == -1){ dist[v] = dist[u] + 1; q.push(v); } } } for(int j = 0; j < N; j ++){ ans += dist[j]; } printf("%lld\n", ans); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 19 ms | 13056 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 206 ms | 14404 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 135 ms | 37560 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 164 ms | 50732 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 222 ms | 60628 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |