Submission #580106

# Submission time Handle Problem Language Result Execution time Memory
580106 2022-06-20T15:22:41 Z AlperenT Zalmoxis (BOI18_zalmoxis) C++17
0 / 100
134 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;

int n, k, arr[N], onecnt[N], needcnt;

struct Item{
	int x;

	vector<int> nums;
};

deque<Item> a, b;
deque<int> newnums[N];

vector<int> v, ans;

bool caninc[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];

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

	for(int num = 1; num <= 29; num++){
		swap(a, b);
		a.clear();

		while(!b.empty()){
			if(b[0].x == num){
				if(b.size() >= 2 && b[1].x == num){
					vector<int> tmp;

					for(auto i : b[0].nums) tmp.push_back(i);
					for(auto i : b[1].nums) tmp.push_back(i);

					a.push_back({num + 1, tmp});
					b.pop_front(), b.pop_front();
				}
				else{
					vector<int> tmp = b[0].nums;

					tmp.push_back(num);

					a.push_back({num + 1, tmp});

					b.pop_front();
				}
			}
			else{
				a.push_back({b[0].x, b[0].nums});
				b.pop_front();
			}
		}
	}

	v = a[0].nums;

	for(int i = 0; i < v.size(); i++) newnums[i].push_back(v[i]);

	needcnt = (n + k) - v.size();

	int ptr = 0;

	for(int i = 0; i < v.size(); i++){
		if(ptr < n && v[i] == arr[i]) ptr++;
		else caninc[i] = true;
	}

	for(int i = 0; i < v.size(); i++){
		if(caninc[i]){
			while(needcnt > 0 && !newnums[i].empty()){
				if(newnums[i].front() == 1){
					onecnt[i]++;
					newnums[i].pop_front();
				}
				else{
					int x = newnums[i].front();

					newnums[i].pop_front();

					needcnt--;

					newnums[i].push_front(x - 1);
					newnums[i].push_front(x - 1);
				}
			}
		}
	}

	for(int i = 0; i < v.size(); i++){
		for(int j = 0; j < onecnt[i]; j++) ans.push_back(1);

		for(auto j : newnums[i]) ans.push_back(j);
	}

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

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:67:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for(int i = 0; i < v.size(); i++) newnums[i].push_back(v[i]);
      |                 ~~^~~~~~~~~~
zalmoxis.cpp:73:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for(int i = 0; i < v.size(); i++){
      |                 ~~^~~~~~~~~~
zalmoxis.cpp:78:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |  for(int i = 0; i < v.size(); i++){
      |                 ~~^~~~~~~~~~
zalmoxis.cpp:99:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |  for(int i = 0; i < v.size(); i++){
      |                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 123 ms 262144 KB Execution killed with signal 9
2 Runtime error 113 ms 262144 KB Execution killed with signal 9
3 Runtime error 129 ms 262144 KB Execution killed with signal 9
4 Runtime error 113 ms 262144 KB Execution killed with signal 9
5 Runtime error 110 ms 262144 KB Execution killed with signal 9
6 Runtime error 109 ms 262144 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 108 ms 262144 KB Execution killed with signal 9
2 Runtime error 123 ms 262144 KB Execution killed with signal 9
3 Runtime error 116 ms 262144 KB Execution killed with signal 9
4 Runtime error 116 ms 262144 KB Execution killed with signal 9
5 Runtime error 116 ms 262144 KB Execution killed with signal 9
6 Runtime error 133 ms 262144 KB Execution killed with signal 9
7 Runtime error 111 ms 262144 KB Execution killed with signal 9
8 Runtime error 115 ms 262144 KB Execution killed with signal 9
9 Runtime error 129 ms 262144 KB Execution killed with signal 9
10 Runtime error 117 ms 262144 KB Execution killed with signal 9
11 Runtime error 117 ms 262144 KB Execution killed with signal 9
12 Runtime error 115 ms 262144 KB Execution killed with signal 9
13 Runtime error 134 ms 262144 KB Execution killed with signal 9
14 Runtime error 130 ms 262144 KB Execution killed with signal 9