답안 #289796

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
289796 2020-09-03T05:11:30 Z duckmoon99 Zalmoxis (BOI18_zalmoxis) C++17
95 / 100
183 ms 8292 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> ii;
typedef vector <ii> vii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

/*
5 1
29 27 25 25 28
*/

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	int x;
	stack<int> s, curr;
	int ans[n+k];
	int idx = n+k-1;
	for(int i = 0; i < n; i++){
		cin >> x;
		s.push(x);
	}
	curr.push(30);
	while(!s.empty()){
		if(curr.empty() || idx<=-1){
			cout << -1 << '\n';
			return 0;
		}
		//printf("curr.top:%d s.top:%d idx:%d\n",curr.top(),s.top(),idx);
		x = curr.top();
		curr.pop();
		if(x<s.top()){
			ans[idx]=x;
			idx--;
		}else if(x==s.top()){
			ans[idx]=x;
			idx--;
			s.pop();
		}else{
			curr.push(x-1);
			curr.push(x-1);
		}
	}
	while(idx>=0){
		if(int(curr.size())>idx+1 || curr.empty()){ 
			cout << -1 <<'\n';
			return 0;
		}else if(int(curr.size())==idx+1){
			ans[idx]=curr.top();
			curr.pop();
			idx--;
		}else{
			if(curr.top() == 0){
				ans[idx]=curr.top();
				curr.pop();
				idx--;
			}else{
				x=curr.top();
				curr.pop();
				curr.push(x-1);
				curr.push(x-1);
			}
		}
	}
	
	for(int i = 0; i < n+k; i++){
		cout<<ans[i]<<" ";
	}
	cout<<'\n';
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 175 ms 6576 KB Output is correct
2 Correct 179 ms 6576 KB Output is correct
3 Correct 174 ms 6704 KB Output is correct
4 Correct 181 ms 6580 KB Output is correct
5 Correct 183 ms 6576 KB Output is correct
6 Correct 175 ms 6576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 176 ms 6580 KB Output is correct
2 Correct 177 ms 6564 KB Output is correct
3 Incorrect 98 ms 4696 KB Unexpected end of file - int32 expected
4 Correct 175 ms 6576 KB Output is correct
5 Correct 179 ms 6580 KB Output is correct
6 Correct 173 ms 6628 KB Output is correct
7 Correct 172 ms 6576 KB Output is correct
8 Correct 174 ms 6560 KB Output is correct
9 Correct 161 ms 8292 KB Output is correct
10 Correct 125 ms 7364 KB Output is correct
11 Correct 139 ms 8228 KB Output is correct
12 Correct 104 ms 6264 KB Output is correct
13 Correct 105 ms 6264 KB Output is correct
14 Correct 102 ms 6264 KB Output is correct