Submission #60001

# Submission time Handle Problem Language Result Execution time Memory
60001 2018-07-23T12:00:51 Z Kerim Zalmoxis (BOI18_zalmoxis) C++17
65 / 100
453 ms 14716 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();
		}
		assert(v.back()>=1);
		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;
		}	
	}puts("");
	return 0;
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:61: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:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&arr[i]);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 248 ms 14252 KB Output is correct
2 Correct 453 ms 14416 KB Output is correct
3 Correct 266 ms 14416 KB Output is correct
4 Correct 337 ms 14560 KB Output is correct
5 Correct 274 ms 14560 KB Output is correct
6 Correct 387 ms 14560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 286 ms 14592 KB Output is correct
2 Correct 365 ms 14592 KB Output is correct
3 Incorrect 393 ms 14620 KB Unexpected end of file - int32 expected
4 Correct 337 ms 14716 KB Output is correct
5 Correct 438 ms 14716 KB Output is correct
6 Correct 377 ms 14716 KB Output is correct
7 Correct 360 ms 14716 KB Output is correct
8 Correct 295 ms 14716 KB Output is correct
9 Incorrect 317 ms 14716 KB Unexpected end of file - int32 expected
10 Incorrect 187 ms 14716 KB Unexpected end of file - int32 expected
11 Incorrect 188 ms 14716 KB Unexpected end of file - int32 expected
12 Incorrect 88 ms 14716 KB Unexpected end of file - int32 expected
13 Incorrect 87 ms 14716 KB Unexpected end of file - int32 expected
14 Incorrect 107 ms 14716 KB Unexpected end of file - int32 expected