답안 #59950

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59950 2018-07-23T11:11:31 Z Kerim Zalmoxis (BOI18_zalmoxis) C++17
65 / 100
463 ms 14596 KB
#include "bits/stdc++.h"
#define MAXN 1000009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
stack<int>st;
int arr[MAXN];
void relax(){
	while(!st.empty()){
		int a=st.top();st.pop();
		if(st.empty()){
			st.push(a);
			break;
		}
		int b=st.top();
		if(a==b){
			st.pop();
			st.push(a+1);
		}
		else{
			st.push(a);	
			break;
		}
	}
}
void solve(int x,int y){
	vector<int>v,g;
	v.pb(x);
	while(y){
		if(!v.size()){
			swap(v,g);
			g.clear();
		}
		g.pb(v.back()-1);
		g.pb(v.back()-1);
		v.ppb();y--;
	}
	tr(it,v)
		printf("%d ",*it);
	tr(it,g)
		printf("%d ",*it);
}
int main(){
    //~ freopen("file.in", "r", stdin);
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
		scanf("%d",&arr[i]);
	st.push(INF);
	vector<PII>ans;
	for(int i=1;i<=n;i++){
		while(st.top()<arr[i]){
			int tmp=st.top();
			st.pop();
			st.push(tmp+1);
			ans.pb(mp(tmp,1));k--;
			relax();
		}
		ans.pb(mp(arr[i],0));
		st.push(arr[i]);
		relax();
	}	
	while(!st.empty()){
		int nd=st.top();st.pop();
		if(nd==30)
			break;
		ans.pb(mp(nd,1));k--;	
		st.push(nd+1);
		relax();
	}
	assert(k>=0);
	tr(it,ans){
		if(it->ss==0)
			printf("%d ",it->ff);
		else{
			if((1<<it->ff)<=k){
				k-=(1<<it->ff);
				for(int j=0;j<(1<<it->ff);j++)
					printf("0 ");
			}
			else
				solve(it->ff,k),k=0;
		}	
	}
	return 0;
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~
zalmoxis.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&arr[i]);
   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 354 ms 14196 KB Output is correct
2 Correct 275 ms 14284 KB Output is correct
3 Correct 344 ms 14348 KB Output is correct
4 Correct 296 ms 14348 KB Output is correct
5 Correct 261 ms 14384 KB Output is correct
6 Correct 287 ms 14384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 299 ms 14384 KB Output is correct
2 Correct 274 ms 14412 KB Output is correct
3 Incorrect 305 ms 14412 KB Unexpected end of file - int32 expected
4 Correct 463 ms 14448 KB Output is correct
5 Correct 294 ms 14448 KB Output is correct
6 Correct 320 ms 14448 KB Output is correct
7 Correct 319 ms 14540 KB Output is correct
8 Correct 372 ms 14596 KB Output is correct
9 Incorrect 246 ms 14596 KB Unexpected end of file - int32 expected
10 Incorrect 150 ms 14596 KB Unexpected end of file - int32 expected
11 Incorrect 220 ms 14596 KB Unexpected end of file - int32 expected
12 Incorrect 139 ms 14596 KB Unexpected end of file - int32 expected
13 Incorrect 95 ms 14596 KB Unexpected end of file - int32 expected
14 Incorrect 90 ms 14596 KB Unexpected end of file - int32 expected