답안 #431197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
431197 2021-06-17T10:14:48 Z faresbasbs Zalmoxis (BOI18_zalmoxis) C++14
5 / 100
505 ms 57308 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 || val == 0){
		for(int i = 0 ; i < 31 ; i += 1){
			if(freq & (1<<i)){
				v[r].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;
	for(int i = 1 ; i <= n ; i += 1){
		cin >> arr[i];
	}
	solve(1,n,30,1);
	vector<pair<int,int>> varr;
	for(int i = 0 ; i <= n ; i += 1){
		if(i){
			varr.push_back({arr[i],1});
		}
		for(auto j : v[i]){
			varr.push_back({j,0});
		}
	}
	vector<int> ans;
	while(k > 0){
		if(varr.back().second == 1){
			ans.push_back(varr.back().first);
			varr.pop_back();
			continue;
		}
		if(varr.back().first > 0){
			k -= 1;
			int a = varr.back().first;
			varr.pop_back();
			varr.push_back({a-1,0}),varr.push_back({a-1,0});
		}else{
			ans.push_back(varr.back().first);
			varr.pop_back();
		}
	}
	while(varr.size()){
		ans.push_back(varr.back().first);
		varr.pop_back();
	}
	reverse(ans.begin(),ans.end());
	for(auto i : ans){
		cout << i << " ";
	}cout << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 467 ms 51800 KB Expected EOF
2 Incorrect 445 ms 47268 KB Expected EOF
3 Incorrect 471 ms 47516 KB Expected EOF
4 Incorrect 451 ms 47424 KB Expected EOF
5 Incorrect 440 ms 47388 KB Expected EOF
6 Incorrect 468 ms 52188 KB Expected EOF
# 결과 실행 시간 메모리 Grader output
1 Incorrect 445 ms 47488 KB Expected EOF
2 Incorrect 457 ms 51952 KB Expected EOF
3 Incorrect 499 ms 47280 KB Expected EOF
4 Incorrect 445 ms 47272 KB Expected EOF
5 Incorrect 459 ms 47528 KB Expected EOF
6 Incorrect 491 ms 47608 KB Expected EOF
7 Incorrect 487 ms 47360 KB Expected EOF
8 Incorrect 505 ms 47084 KB Expected EOF
9 Incorrect 455 ms 57308 KB Expected EOF
10 Incorrect 296 ms 44792 KB not a zalsequence
11 Incorrect 377 ms 53952 KB Expected EOF
12 Incorrect 143 ms 29736 KB not a zalsequence
13 Incorrect 170 ms 29784 KB not a zalsequence
14 Correct 143 ms 29740 KB Output is correct