Submission #580255

# Submission time Handle Problem Language Result Execution time Memory
580255 2022-06-20T20:36:59 Z AlperenT Zalmoxis (BOI18_zalmoxis) C++17
5 / 100
651 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e6 + 5;

int n, k, arr[N], lftcnt;

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

vector<int> nums[N], vec, ans;

bool req[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 num = 1; num <= 29; num++){
		swap(v, v2);
		v.clear();

		for(auto p : v2){
			if(v.empty()) v.push_back(p);
			else{
				if(v.back().first == num){
					if(p.first == num){
						v.back().first = num + 1;
						v.back().second = p.second;
					}
					else{
						v.back().first = num + 1;
						nums[v.back().second].push_back(num);
						v.push_back(p);
					}
				}
				else v.push_back(p);
			}
		}

		if(v.back().first == num){
			v.back().first = num + 1;
			nums[v.back().second].push_back(num);
		}
	}

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

	int ptr = 0;

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

	lftcnt = (n + k) - vec.size();

	for(int i = 0; i < vec.size(); i++){
		if(!req[i] && lftcnt){
			int lftlog = __lg(lftcnt + 1);

			if(vec[i] - lftlog <= 1){
				for(int j = 0; j < (1 << (vec[i] - 1)); j++) ans.push_back(1);

				lftcnt -= (1 << (vec[i] - 1)) - 1;
			}
			else{
				vector<int> tmp;

				for(int j = 0; j < (1 << lftlog); j++) tmp.push_back(vec[i] - lftlog);

				lftcnt -= (1 << lftlog) - 1;

				while(lftcnt > 0){
					ans.push_back(tmp.back() - 1);
					ans.push_back(tmp.back() - 1);

					lftcnt--;

					tmp.pop_back();
				}

				for(auto j : tmp) ans.push_back(j);
			}
		}
		else ans.push_back(vec[i]);
	}

	for(auto i : ans) cout << i << " ";
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:64:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for(int i = 0; i < vec.size(); i++){
      |                 ~~^~~~~~~~~~~~
zalmoxis.cpp:70:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |  for(int i = 0; i < vec.size(); i++){
      |                 ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 485 ms 233496 KB Execution killed with signal 11
2 Runtime error 651 ms 262144 KB Execution killed with signal 9
3 Runtime error 448 ms 231828 KB Execution killed with signal 11
4 Runtime error 400 ms 231236 KB Execution killed with signal 11
5 Runtime error 530 ms 230644 KB Execution killed with signal 11
6 Runtime error 467 ms 236452 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 481 ms 232692 KB Execution killed with signal 6
2 Runtime error 437 ms 235748 KB Execution killed with signal 11
3 Runtime error 401 ms 229620 KB Execution killed with signal 11
4 Runtime error 522 ms 262144 KB Execution killed with signal 9
5 Runtime error 411 ms 230968 KB Execution killed with signal 11
6 Runtime error 399 ms 232768 KB Execution killed with signal 11
7 Runtime error 431 ms 230376 KB Execution killed with signal 6
8 Runtime error 505 ms 262144 KB Execution killed with signal 9
9 Runtime error 511 ms 262144 KB Execution killed with signal 9
10 Incorrect 303 ms 76020 KB not a zalsequence
11 Runtime error 439 ms 262144 KB Execution killed with signal 9
12 Incorrect 97 ms 55176 KB not a zalsequence
13 Incorrect 99 ms 55152 KB not a zalsequence
14 Correct 110 ms 55248 KB Output is correct