답안 #580155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580155 2022-06-20T16:19:58 Z AlperenT Zalmoxis (BOI18_zalmoxis) C++17
0 / 100
1000 ms 141768 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;
};

vector<Item> a, b;
vector<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[b.size() - 1].x == num){
				if(b.size() >= 2 && b[b.size() - 2].x == num){
					vector<int> tmp;

					for(auto i : b[b.size() - 2].nums) tmp.push_back(i);
					for(auto i : b[b.size() - 1].nums) tmp.push_back(i);

					a.push_back({num + 1, tmp});
					b.pop_back(), b.pop_back();
				}
				else{
					vector<int> tmp;

					tmp.push_back(num);

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

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

					b.pop_back();
				}
			}
			else{
				a.push_back({b[b.size() - 1].x, b[b.size() - 1].nums});
				b.pop_back();
			}
		}

		reverse(a.begin(), a.end());
	}

	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].back() == 1){
					onecnt[i]++;
					newnums[i].pop_back();
				}
				else{
					int x = newnums[i].back();

					newnums[i].pop_back();

					needcnt--;

					newnums[i].push_back(x - 1);
					newnums[i].push_back(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:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |  for(int i = 0; i < v.size(); i++) newnums[i].push_back(v[i]);
      |                 ~~^~~~~~~~~~
zalmoxis.cpp:77:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |  for(int i = 0; i < v.size(); i++){
      |                 ~~^~~~~~~~~~
zalmoxis.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |  for(int i = 0; i < v.size(); i++){
      |                 ~~^~~~~~~~~~
zalmoxis.cpp:103:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |  for(int i = 0; i < v.size(); i++){
      |                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 141640 KB Time limit exceeded
2 Execution timed out 1087 ms 141624 KB Time limit exceeded
3 Execution timed out 1090 ms 141560 KB Time limit exceeded
4 Execution timed out 1091 ms 141556 KB Time limit exceeded
5 Execution timed out 1088 ms 141632 KB Time limit exceeded
6 Execution timed out 1073 ms 141760 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1079 ms 141652 KB Time limit exceeded
2 Execution timed out 1082 ms 141504 KB Time limit exceeded
3 Execution timed out 1090 ms 141504 KB Time limit exceeded
4 Execution timed out 1102 ms 141560 KB Time limit exceeded
5 Execution timed out 1089 ms 141768 KB Time limit exceeded
6 Execution timed out 1078 ms 141684 KB Time limit exceeded
7 Execution timed out 1097 ms 141636 KB Time limit exceeded
8 Execution timed out 1076 ms 141552 KB Time limit exceeded
9 Incorrect 995 ms 128008 KB doesn't contain S as a subsequence
10 Incorrect 423 ms 68964 KB doesn't contain S as a subsequence
11 Incorrect 689 ms 83464 KB doesn't contain S as a subsequence
12 Incorrect 94 ms 29820 KB doesn't contain S as a subsequence
13 Incorrect 13 ms 23764 KB Unexpected end of file - int32 expected
14 Incorrect 94 ms 29848 KB not a zalsequence