답안 #431009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
431009 2021-06-17T08:52:31 Z faresbasbs Zalmoxis (BOI18_zalmoxis) C++14
0 / 100
517 ms 48556 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> v[1000001];
int n,k,arr[1000001];

void solve(int l , int r , int val , int freq){
	if(r == l-1){
		for(int i = 0 ; i < 30 ; i += 1){
			if(freq & (1<<i)){
				v[l].push_back(val+i);
				k -= 1;
			}
		}
		return ;
	}
	int pos = -1;
	for(int i = l ; i <= r ; i += 1){
		if(arr[i] == val){
			pos = i;
			break;
		}
	}
	if(pos == -1){
		solve(l,r,val-1,2*freq);
		return ;
	}
	int farr[31];
	memset(farr,0,sizeof farr);
	for(int i = l ; i < pos ; i += 1){
		farr[arr[i]] += 1;
	}
	int tag = 0;
	for(int i = 0 ; i < val ; i += 1){
		farr[i+1] += farr[i]/2;
		if(farr[i]%2 == 1){
			tag = 1;
		}
	}
	freq -= 1;
	solve(l,pos-1,val,farr[val]+tag),solve(pos+1,r,val,freq-farr[val]-tag);
}

int main(){
	cin >> n >> k;
	int kk = k;
	for(int i = 1 ; i <= n ; i += 1){
		cin >> arr[i];
	}
	solve(1,n,30,1);
	vector<int> varr;
	for(int i = 0 ; i <= n ; i += 1){
		for(auto j : v[i]){
			varr.push_back(j);
		}
		if(i){
			varr.push_back(arr[i]);
		}
	}
	vector<int> ans;
	while(k > 0){
		if(varr.back() > 0){
			k -= 1;
			int a = varr.back();
			varr.pop_back();
			varr.push_back(a-1),varr.push_back(a-1);
		}else{
			ans.push_back(varr.back());
			varr.pop_back();
		}
	}
	while(varr.size()){
		ans.push_back(varr.back());
		varr.pop_back();
	}
	reverse(ans.begin(),ans.end());
	for(auto i : ans){
		cout << i << " ";
	}cout << endl;
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:45:6: warning: unused variable 'kk' [-Wunused-variable]
   45 |  int kk = k;
      |      ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 493 ms 37696 KB Unexpected end of file - int32 expected
2 Incorrect 489 ms 37756 KB Unexpected end of file - int32 expected
3 Incorrect 480 ms 37740 KB Unexpected end of file - int32 expected
4 Incorrect 461 ms 37764 KB Unexpected end of file - int32 expected
5 Incorrect 467 ms 37728 KB Unexpected end of file - int32 expected
6 Incorrect 517 ms 37808 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 471 ms 37884 KB Unexpected end of file - int32 expected
2 Incorrect 472 ms 37764 KB Expected EOF
3 Incorrect 472 ms 37812 KB doesn't contain S as a subsequence
4 Incorrect 471 ms 37760 KB Unexpected end of file - int32 expected
5 Incorrect 460 ms 37760 KB Unexpected end of file - int32 expected
6 Incorrect 487 ms 37760 KB Unexpected end of file - int32 expected
7 Incorrect 476 ms 37696 KB Unexpected end of file - int32 expected
8 Incorrect 453 ms 37764 KB Unexpected end of file - int32 expected
9 Incorrect 433 ms 48556 KB Expected EOF
10 Incorrect 252 ms 37992 KB Unexpected end of file - int32 expected
11 Incorrect 361 ms 47276 KB Expected EOF
12 Runtime error 36 ms 48076 KB Execution killed with signal 6
13 Runtime error 36 ms 48096 KB Execution killed with signal 6
14 Runtime error 41 ms 48052 KB Execution killed with signal 6