답안 #867483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867483 2023-10-28T13:33:48 Z pizzamoeger Zalmoxis (BOI18_zalmoxis) C++14
40 / 100
114 ms 20164 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main () {
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	int n, k; cin >> n >> k;
	vector<int> S (n);
	for (int i = 0; i < n; i++) cin >> S[i];

	stack<int> nums;
	vector<pair<int,int>> inserts;
	int i = 0;
	while (i < n) {
		int cur = S[i];
		while (!nums.empty()) {
			int top = nums.top();
			//cerr << cur << " " << top << " " << i << "\n";
			if (cur == top) {
				cur++;
				nums.pop();
			} else if (cur > top) {
				inserts.push_back({i, top});
				cur = top+1;
				nums.pop();
				i--;
			} else {
				nums.push(cur);
				break;
			}
		}
		if (nums.empty()) 	nums.push(cur);
		i++;
	}

	if (!nums.empty() && nums.top() != 30) inserts.push_back({n, nums.top()});

	int left = k-inserts.size();
	int j = 0;
	while (left > 0) {
		while (inserts[j].second == 0) j++;
		inserts[j].second--;
		inserts.push_back(inserts[j]);
		left--;
	}

	sort(inserts.begin(), inserts.end());

	j = 0;
	for (int i = 0; i < n; i++) {
		while (j < inserts.size() && i == inserts[j].first) {
			int cnt = inserts[j].second;
			cout << cnt << " ";
			j++;
		}
		cout << S[i] << " ";
	}
	while (j < inserts.size() && n == inserts[j].first) {
		int cnt = inserts[j].second;
		cout << cnt << " ";
		j++;
	}
	cout << "\n";
}

/*
while (left > 1 && cnt > 1) {
			cnt--;
			cout << cnt << " ";
			left--;
		}
		if (left >= 1) {
			cout << cnt-1 << " " << cnt-1 << " ";
			left--;
		}
		else */

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:54:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   while (j < inserts.size() && i == inserts[j].first) {
      |          ~~^~~~~~~~~~~~~~~~
zalmoxis.cpp:61:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  while (j < inserts.size() && n == inserts[j].first) {
      |         ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 10356 KB Output is correct
2 Correct 99 ms 10280 KB Output is correct
3 Correct 99 ms 10324 KB Output is correct
4 Correct 97 ms 10268 KB Output is correct
5 Correct 98 ms 10324 KB Output is correct
6 Correct 98 ms 10188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 108 ms 10324 KB not a zalsequence
2 Correct 109 ms 10280 KB Output is correct
3 Correct 100 ms 10380 KB Output is correct
4 Incorrect 97 ms 10324 KB not a zalsequence
5 Incorrect 99 ms 10320 KB not a zalsequence
6 Incorrect 100 ms 10336 KB not a zalsequence
7 Incorrect 101 ms 10336 KB not a zalsequence
8 Incorrect 98 ms 10340 KB not a zalsequence
9 Incorrect 102 ms 12448 KB not a zalsequence
10 Incorrect 114 ms 20164 KB not a zalsequence
11 Incorrect 112 ms 14380 KB not a zalsequence
12 Runtime error 1 ms 600 KB Execution killed with signal 6
13 Runtime error 1 ms 604 KB Execution killed with signal 6
14 Incorrect 101 ms 19832 KB not a zalsequence