# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
61913 | 2018-07-27T05:10:33 Z | ainta(#1792) | Zalmoxis (BOI18_zalmoxis) | C++11 | 274 ms | 11544 KB |
#include<cstdio> #include<algorithm> #define N_ 1010000 using namespace std; int n, K, w[N_], s = 0, U[31*N_], cnt; bool v[31 * N_]; void Put(int &s, int b) { if (s&((1 << b) - 1)) { int t = (((s >> b) + 1) << b) - s; for (int j = 0; j <= 30; j++) { if ((t >> j) & 1)U[cnt++] = j; } s += t; } } void Print(int x, int C) { if (C == (1 << x)) { for (int i = 0; i < C; i++)printf("0 "); return; } if (C == 1) { printf("%d ", x); return; } if (C > (1 << (x - 1))) { Print(x - 1, 1 << (x - 1)); Print(x - 1, C - (1 << (x - 1))); } else { Print(x - 1, C - 1); Print(x - 1, 1); } } int main() { int i, j; scanf("%d%d", &n, &K); for (i = 1; i <= n; i++)scanf("%d", &w[i]); for (i = 1; i <= n; i++) { Put(s, w[i]); v[cnt] = 1; U[cnt++] = w[i]; s += (1 << w[i]); } Put(s, 30); int C = K+n - cnt; for (i = 0; i < cnt; i++) { if (v[i] || !C) { printf("%d ", U[i]); continue; } if (C >= (1<<U[i]) - 1) { for (int j = 0; j < (1<<U[i]); j++)printf("0 "); C -= ((1 << U[i]) - 1); continue; } Print(U[i], C+1); C = 0; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 221 ms | 11128 KB | Output is correct |
2 | Correct | 245 ms | 11392 KB | Output is correct |
3 | Correct | 204 ms | 11392 KB | Output is correct |
4 | Correct | 212 ms | 11392 KB | Output is correct |
5 | Correct | 225 ms | 11392 KB | Output is correct |
6 | Correct | 216 ms | 11416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 208 ms | 11456 KB | Output is correct |
2 | Correct | 237 ms | 11456 KB | Output is correct |
3 | Correct | 222 ms | 11456 KB | Output is correct |
4 | Correct | 244 ms | 11456 KB | Output is correct |
5 | Correct | 274 ms | 11456 KB | Output is correct |
6 | Correct | 211 ms | 11456 KB | Output is correct |
7 | Correct | 223 ms | 11456 KB | Output is correct |
8 | Correct | 235 ms | 11544 KB | Output is correct |
9 | Correct | 246 ms | 11544 KB | Output is correct |
10 | Correct | 109 ms | 11544 KB | Output is correct |
11 | Correct | 223 ms | 11544 KB | Output is correct |
12 | Correct | 46 ms | 11544 KB | Output is correct |
13 | Correct | 48 ms | 11544 KB | Output is correct |
14 | Correct | 50 ms | 11544 KB | Output is correct |