Submission #586105

# Submission time Handle Problem Language Result Execution time Memory
586105 2022-06-29T21:31:17 Z AlperenT Zalmoxis (BOI18_zalmoxis) C++17
35 / 100
261 ms 167744 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6;

int n, k, arr[N];

vector<int> nums[N];

vector<pair<int, int>> v, vnext;

vector<int> vec, ans;

bool isneeded[N];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	
	cin >> n >> k;

	for(int i = 0; i < n; i++){
		cin >> arr[i];

		nums[i].push_back(arr[i]);

		v.push_back({arr[i], i});
	}

	for(int cur = 0; cur <= 29; cur++){
		reverse(v.begin(), v.end());

		while(!v.empty()){
			pair<int, int> p = v.back(); v.pop_back();

			if(p.first != cur) vnext.push_back(p);
			else{
				if(!v.empty() && v.back().first == cur){
					vnext.push_back({cur + 1, v.back().second});
					v.pop_back();
				}
				else{
					nums[p.second].push_back(cur);
					vnext.push_back({cur + 1, p.second});
				}
			}
		}

		swap(v, vnext);
		vnext.clear();
	}

	for(int i = 0; i < n; i++){
		for(auto x : nums[i]) vec.push_back(x);
	}

	int ptr = 0;

	for(int i = 0; i < vec.size(); i++){
		if(ptr < n && vec[ptr] == arr[i]) isneeded[i] = true, ptr++;
	}

	assert(ptr == n);

	for(int i = 0; i < vec.size(); i++){
		if(isneeded[i]) ans.push_back(vec[i]);
		else{
			vector<int> stk;

			stk.push_back(vec[i]);

			while(!stk.empty() && ans.size() + (vec.size() - i - 1) + stk.size() < n + k){
				int cur = stk.back(); stk.pop_back();

				if(cur == 0) ans.push_back(0);
				else stk.push_back(cur - 1), stk.push_back(cur - 1);
			}

			while(!stk.empty()){
				ans.push_back(stk.back());
				stk.pop_back();
			}
		}
	}

	// assert(ans.size() == n + k || ans.size() == n + k - 1);

	// cout << ans.size() << "\n";

	for(auto x : ans) cout << x << " ";
	cout << "\n";
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for(int i = 0; i < vec.size(); i++){
      |                 ~~^~~~~~~~~~~~
zalmoxis.cpp:65:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i = 0; i < vec.size(); i++){
      |                 ~~^~~~~~~~~~~~
zalmoxis.cpp:72:73: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   72 |    while(!stk.empty() && ans.size() + (vec.size() - i - 1) + stk.size() < n + k){
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 238 ms 89020 KB Output is correct
2 Correct 247 ms 89280 KB Output is correct
3 Correct 245 ms 89064 KB Output is correct
4 Correct 244 ms 89092 KB Output is correct
5 Correct 224 ms 89108 KB Output is correct
6 Correct 213 ms 88852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 209 ms 166228 KB Execution killed with signal 6
2 Runtime error 216 ms 166656 KB Execution killed with signal 6
3 Runtime error 208 ms 166300 KB Execution killed with signal 6
4 Runtime error 261 ms 167744 KB Execution killed with signal 6
5 Runtime error 214 ms 167532 KB Execution killed with signal 6
6 Runtime error 214 ms 166704 KB Execution killed with signal 6
7 Runtime error 221 ms 166556 KB Execution killed with signal 6
8 Runtime error 211 ms 167712 KB Execution killed with signal 6
9 Runtime error 205 ms 146428 KB Execution killed with signal 6
10 Runtime error 117 ms 86932 KB Execution killed with signal 6
11 Runtime error 149 ms 105032 KB Execution killed with signal 6
12 Runtime error 31 ms 48084 KB Execution killed with signal 6
13 Runtime error 30 ms 48072 KB Execution killed with signal 6
14 Correct 87 ms 29796 KB Output is correct