#include<cstdio>
#include<deque>
#include<vector>
using namespace std;
int n,k;
vector< deque<int> > tree;
int su[100001];
int sons[100001];
int head;
void bubble(int parent){
int i;
for(i=0;i<sons[parent];i++){
bubble(tree[parent][i]);
}
if(sons[parent]<2) return;
head=tree[parent][0];
for(i=1;i<sons[parent];i++){
if(su[head]>su[tree[parent][i]]){
tree[head].push_back(tree[parent][i]);
}else{
tree[tree[parent][i]].push_front(head);
head=tree[parent][i];
}
sons[head]++;
}
tree[parent].clear();
tree[parent].push_back(head);
sons[parent]=1;
}
void aprint(int parent){
int i;
for(i=0;i<sons[parent];i++){
aprint(tree[parent][i]);
}
if(parent>0) printf("%d ",su[parent]);
}
int main(){
int i;
scanf("%d %d",&n,&k);
tree.resize(n+1);
for(i=1;i<=n;i++){
scanf("%d",&su[i]);
tree[0].resize(n);
tree[0][i-1]=i;
}
sons[0]=n;
for(i=0;i<k;i++) bubble(0);
aprint(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2376 KB |
Output is correct |
2 |
Correct |
0 ms |
2376 KB |
Output is correct |
3 |
Correct |
0 ms |
2376 KB |
Output is correct |
4 |
Correct |
0 ms |
2376 KB |
Output is correct |
5 |
Correct |
0 ms |
2376 KB |
Output is correct |
6 |
Correct |
0 ms |
2376 KB |
Output is correct |
7 |
Correct |
0 ms |
2376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
4252 KB |
Output is correct |
2 |
Correct |
234 ms |
4712 KB |
Output is correct |
3 |
Correct |
110 ms |
4548 KB |
Output is correct |
4 |
Correct |
0 ms |
2640 KB |
Output is correct |
5 |
Correct |
0 ms |
3724 KB |
Output is correct |
6 |
Correct |
83 ms |
4404 KB |
Output is correct |
7 |
Correct |
23 ms |
4120 KB |
Output is correct |
8 |
Correct |
5 ms |
3856 KB |
Output is correct |
9 |
Correct |
67 ms |
4388 KB |
Output is correct |
10 |
Correct |
6 ms |
3036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Memory limit exceeded |
39 ms |
65536 KB |
Memory limit exceeded |
2 |
Memory limit exceeded |
52 ms |
65536 KB |
Memory limit exceeded |
3 |
Memory limit exceeded |
28 ms |
65536 KB |
Memory limit exceeded |
4 |
Memory limit exceeded |
41 ms |
65536 KB |
Memory limit exceeded |
5 |
Memory limit exceeded |
31 ms |
65536 KB |
Memory limit exceeded |
6 |
Memory limit exceeded |
20 ms |
65536 KB |
Memory limit exceeded |
7 |
Memory limit exceeded |
54 ms |
65536 KB |
Memory limit exceeded |
8 |
Memory limit exceeded |
20 ms |
65536 KB |
Memory limit exceeded |
9 |
Memory limit exceeded |
52 ms |
65536 KB |
Memory limit exceeded |
10 |
Memory limit exceeded |
32 ms |
65536 KB |
Memory limit exceeded |
11 |
Execution timed out |
1000 ms |
65232 KB |
Program timed out |
12 |
Execution timed out |
1000 ms |
59420 KB |
Program timed out |
13 |
Execution timed out |
1000 ms |
31348 KB |
Program timed out |
14 |
Memory limit exceeded |
32 ms |
65536 KB |
Memory limit exceeded |
15 |
Execution timed out |
1000 ms |
52992 KB |
Program timed out |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
52900 KB |
Program timed out |
2 |
Memory limit exceeded |
48 ms |
65536 KB |
Memory limit exceeded |
3 |
Memory limit exceeded |
64 ms |
65536 KB |
Memory limit exceeded |
4 |
Memory limit exceeded |
47 ms |
65536 KB |
Memory limit exceeded |
5 |
Execution timed out |
1000 ms |
65220 KB |
Program timed out |
6 |
Memory limit exceeded |
62 ms |
65536 KB |
Memory limit exceeded |
7 |
Memory limit exceeded |
27 ms |
65536 KB |
Memory limit exceeded |
8 |
Execution timed out |
1000 ms |
31188 KB |
Program timed out |
9 |
Memory limit exceeded |
38 ms |
65536 KB |
Memory limit exceeded |
10 |
Memory limit exceeded |
28 ms |
65536 KB |
Memory limit exceeded |
11 |
Memory limit exceeded |
39 ms |
65536 KB |
Memory limit exceeded |
12 |
Execution timed out |
1000 ms |
59276 KB |
Program timed out |
13 |
Memory limit exceeded |
35 ms |
65536 KB |
Memory limit exceeded |
14 |
Memory limit exceeded |
31 ms |
65536 KB |
Memory limit exceeded |
15 |
Memory limit exceeded |
38 ms |
65536 KB |
Memory limit exceeded |