# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
569439 | 2022-05-27T11:48:48 Z | 79brue | Teleporters (IOI08_teleporters) | C++17 | 806 ms | 25852 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, k, len; int nxt[2000002]; bool visited[2000002]; int l[1000002], r[1000002]; vector<int> vec; int base; int main(){ scanf("%d %d", &n, &k); for(int i=1; i<=n; i++){ scanf("%d %d", &l[i], &r[i]); vec.push_back(l[i]), vec.push_back(r[i]); } sort(vec.begin(), vec.end()); len = n*2; for(int i=0; i<len; i++) nxt[i] = i+1; for(int i=1; i<=n; i++){ l[i] = lower_bound(vec.begin(), vec.end(), l[i]) - vec.begin() + 1; r[i] = lower_bound(vec.begin(), vec.end(), r[i]) - vec.begin() + 1; nxt[l[i]-1] = r[i]; nxt[r[i]-1] = l[i]; } nxt[len] = 0; vec.clear(); for(int i=0; i<=len; i++){ if(visited[i]) continue; int x = i, cnt = 0; while(!visited[x]){ visited[x] = 1; cnt++; x = nxt[x]; } if(i==0) base = cnt; else vec.push_back(cnt); } sort(vec.begin(), vec.end()); --base; while(k){ if(vec.empty()) break; else base += vec.back() + 2, vec.pop_back(); k--; } base += k*2; printf("%d", base); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 340 KB | Output is correct |
2 | Correct | 6 ms | 744 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 780 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 848 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 77 ms | 3536 KB | Output is correct |
2 | Correct | 207 ms | 8068 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 170 ms | 5796 KB | Output is correct |
2 | Incorrect | 318 ms | 11728 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 506 ms | 16204 KB | Output is correct |
2 | Correct | 606 ms | 19408 KB | Output is correct |
3 | Correct | 684 ms | 21244 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 798 ms | 22740 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 806 ms | 25812 KB | Output is correct |
2 | Correct | 753 ms | 25852 KB | Output is correct |
3 | Correct | 416 ms | 25764 KB | Output is correct |
4 | Correct | 760 ms | 25836 KB | Output is correct |