# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
61892 | 2018-07-27T04:36:40 Z | 정원준(#1799) | Zalmoxis (BOI18_zalmoxis) | C++11 | 409 ms | 23832 KB |
#include <bits/stdc++.h> #define L long long using namespace std; L n,k; L ans[1000010],top; L chkm[1000010]; L a[1000010]; stack<L>S; int main() { scanf("%lld %lld",&n,&k); L i; for(i=1;i<=n;i++) { scanf("%lld",&a[i]); L temp=a[i]; while(!S.empty()&&S.top()<temp) { L temp2=S.top();S.pop(); ans[++top]=temp2; chkm[top]=1; temp2++; while(temp2<30&&!S.empty()&&S.top()==temp2) { S.pop(); temp2++; } if(temp2<30) S.push(temp2); } while(temp<30&&!S.empty()&&S.top()==temp) { S.pop(); temp++; } if(temp<30) S.push(temp); ans[++top]=a[i]; } while(!S.empty()) { if(S.top()>=30) S.pop(); else { L temp=S.top();S.pop(); ans[++top]=temp; chkm[top]=1; temp++; while(temp<30&&!S.empty()&&S.top()==temp) { S.pop(); temp++; } if(temp<30) S.push(temp); } } /*for(i=1;i<=top;i++) { printf("%lld ",ans[i]); } puts(""); for(i=1;i<=top;i++) { printf("%lld ",chkm[i]); } puts("");*/ if(top>n+k) while(1); L rem=n+k-top; for(i=1;i<=top;i++) { if(!chkm[i]) printf("%lld ",ans[i]); else { stack<L>invs; S.push(ans[i]); while(rem&&!S.empty()) { L x=S.top();S.pop(); if(x==1) { invs.push(x); continue; } S.push(x-1); S.push(x-1); rem--; } while(!S.empty()) { invs.push(S.top());S.pop(); } while(!invs.empty()) { printf("%lld ",invs.top());invs.pop(); } } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 382 ms | 18148 KB | Output is correct |
2 | Correct | 347 ms | 18184 KB | Output is correct |
3 | Correct | 284 ms | 18184 KB | Output is correct |
4 | Correct | 268 ms | 18184 KB | Output is correct |
5 | Correct | 302 ms | 18228 KB | Output is correct |
6 | Correct | 327 ms | 18260 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 260 ms | 18268 KB | Output is correct |
2 | Correct | 297 ms | 21476 KB | Output is correct |
3 | Correct | 394 ms | 23440 KB | Output is correct |
4 | Correct | 336 ms | 23440 KB | Output is correct |
5 | Correct | 315 ms | 23440 KB | Output is correct |
6 | Correct | 286 ms | 23440 KB | Output is correct |
7 | Correct | 307 ms | 23440 KB | Output is correct |
8 | Correct | 278 ms | 23440 KB | Output is correct |
9 | Correct | 409 ms | 23832 KB | Output is correct |
10 | Correct | 236 ms | 23832 KB | Output is correct |
11 | Correct | 246 ms | 23832 KB | Output is correct |
12 | Correct | 179 ms | 23832 KB | Output is correct |
13 | Correct | 195 ms | 23832 KB | Output is correct |
14 | Correct | 170 ms | 23832 KB | Output is correct |