# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
756894 | 2023-06-12T11:07:42 Z | KN200711 | medians (balkan11_medians) | C++14 | 43 ms | 4292 KB |
# include <bits/stdc++.h> using namespace std; int ct[200001]; int mn, mx, N; void upd() { while(ct[mn] && mn <= N) mn++; while(ct[mx] && mx > 0) mx--; } int main() { scanf("%d", &N); vector<int> arr(N); for(int i=0;i<N;i++) scanf("%d", &arr[i]); vector<int> as; as.clear(); mn = 1; mx = 2 * N - 1; for(int i=0;i<N;i++) { if(i == 0) { as.push_back(arr[i]); ct[arr[i]]++; } else { upd(); if(ct[arr[i]]) { if(arr[i] > arr[i - 1]) { as.push_back(mx); ct[mx] = 1; upd(); as.push_back(mx); } else if(arr[i] < arr[i - 1]) { as.push_back(mn); ct[mn] = 1; upd(); as.push_back(mn); } else { as.push_back(mn); as.push_back(mx); } } else { if(arr[i] > arr[i - 1]) { as.push_back(arr[i]); as.push_back(mx); } else if(arr[i] < arr[i - 1]) { as.push_back(arr[i]); as.push_back(mn); } else { as.push_back(mn); as.push_back(mx); } } ct[as.back()] = 1; ct[as[as.size() - 2]] = 1; } } for(int p=0;p<as.size();p++) printf("%d ", as[p]); printf("\n"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 312 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 308 KB | Output is correct |
8 | Correct | 1 ms | 312 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 320 KB | Output is correct |
2 | Correct | 3 ms | 468 KB | Output is correct |
3 | Correct | 3 ms | 596 KB | Output is correct |
4 | Correct | 9 ms | 980 KB | Output is correct |
5 | Correct | 11 ms | 1552 KB | Output is correct |
6 | Correct | 22 ms | 2820 KB | Output is correct |
7 | Correct | 43 ms | 4292 KB | Output is correct |