답안 #861855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861855 2023-10-17T05:14:24 Z maks007 Zalmoxis (BOI18_zalmoxis) C++14
35 / 100
1000 ms 60972 KB
#include "bits/stdc++.h"

using namespace std;

#define int long long

int k;
vector <pair <int,int>> ans;
vector <int> a;

void decomp(int v) {
	stack <int> st;
	st.push(v);
	while(k --) {
		if(st.size() == 0) break;
		int v = st.top();
		st.pop();
		if(v == 0) {
			cout << 0 << " ";
			k ++;
			continue;
		}
		st.push(v-1);
		st.push(v-1);
	}
	while(st.size()) cout << st.top() << " ", st.pop();
}

void f(int v) {
	if(a.size() == 0) {
		ans.push_back({v, 1});
		return;
	}
	if(v == a.back()) {
		ans.push_back({v,0});
		a.pop_back();
		return;
	}
	if(a.back() > v) {
		ans.push_back({v,1});
		return;
	}
	f(v-1);
	f(v-1);
}

signed main () {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, cnt = 0;
	cin >> n >> k;
	for(int i = 0; i < n; i ++) {
		int x;
		cin >> x;
		a.push_back(x);
	}
	reverse(a.begin(), a.end());

	f(30);
	for(auto i : ans) k -= i.second;
	for(auto i : ans) {
		if(i.second == 0) cout << i.first << " ";
		else if(k){
			decomp(i.first);
		}else cout << i.first << " ";
	}
	return 0;
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:50:9: warning: unused variable 'cnt' [-Wunused-variable]
   50 |  int n, cnt = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 26428 KB Output is correct
2 Correct 104 ms 26680 KB Output is correct
3 Correct 104 ms 26116 KB Output is correct
4 Correct 105 ms 26940 KB Output is correct
5 Correct 106 ms 26160 KB Output is correct
6 Correct 104 ms 26292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 302 ms 34036 KB Expected EOF
2 Correct 105 ms 26152 KB Output is correct
3 Incorrect 173 ms 28976 KB Expected EOF
4 Incorrect 516 ms 42024 KB Expected EOF
5 Incorrect 188 ms 29208 KB Expected EOF
6 Incorrect 269 ms 32688 KB Expected EOF
7 Incorrect 347 ms 35756 KB Expected EOF
8 Incorrect 134 ms 27180 KB Expected EOF
9 Execution timed out 1053 ms 60972 KB Time limit exceeded
10 Execution timed out 1047 ms 49788 KB Time limit exceeded
11 Execution timed out 1056 ms 55980 KB Time limit exceeded
12 Execution timed out 1061 ms 40972 KB Time limit exceeded
13 Execution timed out 1069 ms 41228 KB Time limit exceeded
14 Execution timed out 1073 ms 41060 KB Time limit exceeded