# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
78941 | 2018-10-09T16:43:48 Z | bogdan10bos | Zalmoxis (BOI18_zalmoxis) | C++14 | 257 ms | 32660 KB |
#include <bits/stdc++.h> using namespace std; //#define FILE_IO int N, K, M; int v[1000005]; vector<int> stv, add[1000005]; int printmore(int x, int need) { if(x == 0) { printf("%d ", x); return 0; } if(need == 0) { printf("%d ", x); return 0; } if(need == 1) { printf("%d %d ", x - 1, x - 1); return 1; } need--; int lft = need / 2; int rgt = need - lft; int tot = printmore(x - 1, lft) + printmore(x - 1, rgt) + 1; return tot; } int main() { #ifdef FILE_IO freopen("1.in", "r", stdin); freopen("1.out", "w", stdout); #endif scanf("%d%d", &N, &K); for(int i = 1; i <= N; i++) scanf("%d", &v[i]); v[N + 1] = 30; stv.push_back(v[1]); for(int i = 2; i <= N + 1; i++) { while(stv.back() < v[i]) { int val = stv.back(); stv.pop_back(); if(!stv.empty() && stv.back() == val) { stv.pop_back(); stv.push_back(val + 1); continue; } add[i - 1].push_back(val); M++; stv.push_back(val + 1); } while((int)stv.size() > 1) { int x = stv.back(); stv.pop_back(); int y = stv.back(); if(x == y) { stv.pop_back(); stv.push_back(x + 1); continue; } stv.push_back(x); break; } stv.push_back(v[i]); while((int)stv.size() > 1) { int x = stv.back(); stv.pop_back(); int y = stv.back(); if(x == y) { stv.pop_back(); stv.push_back(x + 1); continue; } stv.push_back(x); break; } } assert(M <= K); int more = K - M; for(int i = 1; i <= N; i++) { printf("%d ", v[i]); for(auto x: add[i]) { int pr = printmore(x, more); more -= pr; } } printf("\n"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 243 ms | 29732 KB | Output is correct |
2 | Correct | 238 ms | 29752 KB | Output is correct |
3 | Correct | 257 ms | 29992 KB | Output is correct |
4 | Correct | 252 ms | 29992 KB | Output is correct |
5 | Correct | 243 ms | 29992 KB | Output is correct |
6 | Correct | 236 ms | 29992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 236 ms | 29992 KB | Output is correct |
2 | Correct | 229 ms | 29992 KB | Output is correct |
3 | Correct | 235 ms | 29992 KB | Output is correct |
4 | Correct | 247 ms | 29992 KB | Output is correct |
5 | Correct | 255 ms | 30032 KB | Output is correct |
6 | Correct | 239 ms | 30032 KB | Output is correct |
7 | Correct | 249 ms | 30032 KB | Output is correct |
8 | Correct | 239 ms | 30048 KB | Output is correct |
9 | Correct | 228 ms | 32660 KB | Output is correct |
10 | Correct | 169 ms | 32660 KB | Output is correct |
11 | Correct | 223 ms | 32660 KB | Output is correct |
12 | Correct | 128 ms | 32660 KB | Output is correct |
13 | Correct | 119 ms | 32660 KB | Output is correct |
14 | Correct | 117 ms | 32660 KB | Output is correct |