Submission #586102

# Submission time Handle Problem Language Result Execution time Memory
586102 2022-06-29T21:08:57 Z AlperenT Zalmoxis (BOI18_zalmoxis) C++17
5 / 100
425 ms 241780 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e6 + 5;

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 = 1; 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);

		if(vec.size() >= N) return 31;
	}

	int ptr = 0;

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

	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 == 1) ans.push_back(1);
				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);

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

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

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:61:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  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){
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from zalmoxis.cpp:1:
zalmoxis.cpp:86:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   86 |  assert(ans.size() == n + k);
      |         ~~~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 324 ms 116756 KB Execution failed because the return code was nonzero
2 Runtime error 425 ms 241252 KB Execution killed with signal 6
3 Runtime error 344 ms 116280 KB Execution failed because the return code was nonzero
4 Runtime error 349 ms 116112 KB Execution failed because the return code was nonzero
5 Runtime error 314 ms 115968 KB Execution failed because the return code was nonzero
6 Runtime error 377 ms 117564 KB Execution failed because the return code was nonzero
# Verdict Execution time Memory Grader output
1 Runtime error 324 ms 116500 KB Execution failed because the return code was nonzero
2 Runtime error 330 ms 117336 KB Execution failed because the return code was nonzero
3 Runtime error 314 ms 115732 KB Execution failed because the return code was nonzero
4 Runtime error 421 ms 241780 KB Execution killed with signal 6
5 Runtime error 316 ms 115968 KB Execution failed because the return code was nonzero
6 Runtime error 318 ms 116468 KB Execution failed because the return code was nonzero
7 Runtime error 349 ms 115860 KB Execution failed because the return code was nonzero
8 Runtime error 410 ms 239196 KB Execution killed with signal 6
9 Runtime error 419 ms 219776 KB Execution killed with signal 6
10 Incorrect 232 ms 75032 KB doesn't contain S as a subsequence
11 Runtime error 297 ms 180152 KB Execution killed with signal 6
12 Incorrect 98 ms 53300 KB doesn't contain S as a subsequence
13 Incorrect 95 ms 53392 KB doesn't contain S as a subsequence
14 Correct 98 ms 53284 KB Output is correct