Submission #867457

# Submission time Handle Problem Language Result Execution time Memory
867457 2023-10-28T12:29:07 Z 42kangaroo Zalmoxis (BOI18_zalmoxis) C++17
30 / 100
123 ms 19276 KB
//
// Created by 42kangaroo on 28/10/2023.
//
#include "bits/stdc++.h"

using namespace std;

#define int long long

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, k; cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	vector<pair<int,int>> addBef;
	stack<pair<int,int>> st;
	auto mergeBack= [&st](){
		while (st.size()> 1){
			auto t = st.top();
			st.pop();
			if (st.top().second == t.second) {
				st.top().second++;
			} else {
				st.push(t);
				break;
			}
		}
	};
	for (int i = 0; i < n; ++i) {
		while (!st.empty() && st.top().second < a[i]) {
			addBef.push_back(st.top());
			st.push({-1, st.top().second});
			mergeBack();
		}
		st.push({i, a[i]});
		mergeBack();
	}
	while (!st.empty() && st.top().second < 30) {
		addBef.push_back(st.top());
		st.push({-1, st.top().second});
		mergeBack();
	}
	vector<int> out;
	int addInd = 0;
	bool first = true;
	assert(!addBef.empty());
	for (int i = 0; i < n; ++i) {
		vector<int> hasTo;
		while (addInd < addBef.size() && addBef[addInd].first == i) {
			hasTo.push_back(addBef[addInd].second);
			addInd++;
		}
		for (int q = 0; q < hasTo.size(); ++q) {
			if (first) {
				int ks = k - addBef.size() + 1;
				int p2 = 1;
				for (int j = 0; j <= 30; ++j, p2*= 2) {
					if (p2 >= ks) {
						for (int l = 0; l < ks; ++l) {
							if (l < p2 - ks - 1) out.push_back(hasTo[q] - j - 1);
							else out.push_back(hasTo[q] - j);
						}
						break;
					}
				}
				first = false;
			} else {
				out.push_back(hasTo[q]);
			}
		}
		out.push_back(a[i]);
	}
	for (auto e: out) {
		cout << e << " ";
	}
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:52:17: 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]
   52 |   while (addInd < addBef.size() && addBef[addInd].first == i) {
      |          ~~~~~~~^~~~~~~~~~~~~~~
zalmoxis.cpp:56:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for (int q = 0; q < hasTo.size(); ++q) {
      |                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 116 ms 18104 KB Output is correct
2 Correct 113 ms 18380 KB Output is correct
3 Correct 115 ms 18100 KB Output is correct
4 Correct 114 ms 18136 KB Output is correct
5 Correct 112 ms 18244 KB Output is correct
6 Correct 123 ms 18536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 18120 KB Unexpected end of file - int32 expected
2 Incorrect 109 ms 18180 KB Unexpected end of file - int32 expected
3 Incorrect 110 ms 18356 KB Unexpected end of file - int32 expected
4 Incorrect 111 ms 18356 KB Unexpected end of file - int32 expected
5 Incorrect 110 ms 18124 KB Unexpected end of file - int32 expected
6 Incorrect 109 ms 18124 KB Unexpected end of file - int32 expected
7 Incorrect 111 ms 18100 KB Unexpected end of file - int32 expected
8 Incorrect 111 ms 18360 KB Unexpected end of file - int32 expected
9 Incorrect 102 ms 19276 KB Unexpected end of file - int32 expected
10 Incorrect 70 ms 15940 KB Unexpected end of file - int32 expected
11 Incorrect 85 ms 17772 KB Unexpected end of file - int32 expected
12 Incorrect 53 ms 12204 KB Unexpected end of file - int32 expected
13 Incorrect 53 ms 12248 KB Unexpected end of file - int32 expected
14 Incorrect 54 ms 12416 KB not a zalsequence