# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
330764 | 2020-11-26T13:35:23 Z | BeanZ | medians (balkan11_medians) | C++14 | 300 ms | 2168 KB |
// I_Love_LPL #include <bits/stdc++.h> using namespace std; #define ll int #define endl '\n' const int N = 2e5 + 5; const int lg = 60; const int mod = 998244353; const long long oo = 1e18; const int lim = 1e6 + 5; long double eps = 1e-3; ll vis[N], b[N], a[N]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("A.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; b[1] = a[1]; vis[b[1]] = 1; for (int i = 2; i <= n; i++){ if (vis[a[i]] == 0){ b[i * 2 - 2] = a[i]; vis[a[i]] = 1; ll gr = 0, sm = 0; for (int j = 1; j <= (i * 2 - 2); j++){ if (b[j] < a[i]) sm++; if (b[j] > a[i]) gr++; } if (sm > gr){ for (int j = 2 * n - 1; j >= 1; j--){ if (vis[j]) continue; b[i * 2 - 1] = j; vis[j] = 1; break; } } else { for (int j = 1; j <= (2 * n + 1); j++){ if (vis[j]) continue; b[i * 2 - 1] = j; vis[j] = 1; break; } } } else { ll gr = 0, sm = 0; for (int j = 1; j < (i * 2 - 2); j++){ if (b[j] < a[i]) sm++; if (b[j] > a[i]) gr++; } if (sm > gr){ ll cnt = 2; for (int j = 2 * n - 1; j >= 1; j--){ if (vis[j]) continue; if (cnt == 0) break; b[i * 2 - cnt] = j; vis[j] = 1; cnt--; } } else if (gr > sm) { ll cnt = 2; for (int j = 1; j <= (2 * n - 1); j++){ if (vis[j]) continue; if (cnt == 0) break; b[i * 2 - cnt] = j; vis[j] = 1; cnt--; } } else { ll cnt = 2; for (int j = 1; j <= (2 * n - 1); j++){ if (vis[j]) continue; if (cnt == 1) break; b[i * 2 - cnt] = j; vis[j] = 1; cnt--; } for (int j = 2 * n - 1; j >= 1; j--){ if (vis[j]) continue; if (cnt == 0) break; b[i * 2 - cnt] = j; vis[j] = 1; cnt--; } } } } for (int i = 1; i <= (2 * n - 1); i++) cout << b[i] << " "; } /* */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 2 ms | 364 KB | Output is correct |
13 | Correct | 3 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 492 KB | Output is correct |
2 | Correct | 47 ms | 640 KB | Output is correct |
3 | Correct | 212 ms | 620 KB | Output is correct |
4 | Execution timed out | 828 ms | 1004 KB | Time limit exceeded |
5 | Execution timed out | 1072 ms | 1116 KB | Time limit exceeded |
6 | Execution timed out | 1058 ms | 1668 KB | Time limit exceeded |
7 | Execution timed out | 1091 ms | 2168 KB | Time limit exceeded |