# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
81804 | Plurm | Zalmoxis (BOI18_zalmoxis) | C++11 | 1095 ms | 141712 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int gt;
class node{
public:
node* l;
node* r;
node* lnk;
int key;
int t;
node(int x = -1){
t = ++gt;
key = x;
l = r = lnk = NULL;
}
};
node* ans;
node* ansb;
class Compare{
public:
const bool operator()(node* x,node* y){
return x->key < y->key ? true : x->key == y->key ? x->t < y->t : false;
}
};
int main(){
int n,k;
scanf("%d%d",&n,&k);
set<node*, Compare> ms;
ans = new node(-1); // Head
ansb = ans;
for(int i = 0; i < n; i++){
int cur;
scanf("%d",&cur);
ansb->r = new node(cur);
ansb->r->l = ansb;
if(ansb->lnk) ansb->lnk->r = ansb->r;
ansb = ansb->r;
ansb->lnk = new node(cur);
ansb->lnk->l = ansb->l;
ms.insert(ansb->lnk);
}
ansb->r = new node(-1);
ansb->r->l = ansb;
if(ansb->lnk) ansb->lnk->r = ansb->r;
ansb = ansb->r;
set<node*> v;
while((*ms.begin())->key < 30){
auto cur = *ms.begin();
bool collapsing = false;
if(cur->r != ansb && cur->r->lnk->key == cur->key){
ms.erase(cur);
collapsing = true;
ms.erase(cur->r->lnk);
auto buf = cur->r->lnk->r;
delete cur->r->lnk;
cur->r->lnk = cur;
cur->r = buf;
cur->key++;
ms.insert(cur);
}else if(cur->l != ans && cur->l->lnk->key == cur->key){
ms.erase(cur);
collapsing = true;
ms.erase(cur->l->lnk);
auto buf = cur->l->lnk->l;
delete cur->l->lnk;
cur->l->lnk = cur;
cur->l = buf;
cur->key++;
ms.insert(cur);
}
if(collapsing) continue;
cur->l->r->r->l = new node(cur->l->r->key);
v.insert(cur->l->r->r->l);
cur->l->r->r->l->r = cur->l->r->r;
cur->l->r->r->l->l = cur->l->r;
cur->l->r->r = cur->l->r->r->l;
cur->l->r->key = cur->key;
cur->l->r->r->lnk = new node(cur->key);
ms.insert(cur->l->r->r->lnk);
cur->l->r->r->lnk->l = cur->l->r;
cur->l->r->r->lnk->r = cur->r;
cur->r = cur->l->r->r;
}
node* cur = ans->r;
int cnt = v.size();
while(cur != ansb){
if(v.find(cur) != v.end()){
while(cnt < k && cur->key > 1){
cur->r->l = new node(cur->key-1);
cur->r->l->r = cur->r;
cur->r->l->l = cur;
cur->r = cur->r->l;
cur->key--;
cnt++;
}
}
printf("%d ",cur->key);
cur = cur->r;
}
printf("\n");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |