이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;}
int arr[MAXN];
vector<int>adj[MAXN];
vector<int>vec;
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);
stack<PII>st;
st.push(mp(arr[1],1));
int cnt=0;
for(int i=2;i<=n;i++){
int now=arr[i],ok=0;
while(!ok){
while(!st.empty() and st.top().ff==now){
st.pop();
now++;
}
if(st.empty())
st.push(mp(now,i)),ok=1;
else{
if(st.top().ff<now){
while(st.top().ff<now){
PII tmp=st.top();st.pop();
if(st.empty() or st.top().ff!=tmp.ff)
adj[tmp.ss].pb(tmp.ff),cnt++;
else
st.pop();
st.push(mp(tmp.ff+1,tmp.ss));
}
}
else
st.push(mp(now,i)),ok=1;
}
}
}
while(!st.empty()){
PII tmp=st.top();st.pop();
if(tmp.ff==30)
break;
if(!st.empty() and st.top().ff==tmp.ff)
st.pop();
else
adj[tmp.ss].pb(tmp.ff),cnt++;
st.push(mp(tmp.ff+1,tmp.ss));
}
assert(cnt<=k);
k-=cnt;
for(int i=1;i<=n;i++){
printf("%d ",arr[i]);
tr(it,adj[i]){
if((1<<*it)<=k){
k-=(1<<*it);
for(int j=0;j<(1<<(*it));j++)
printf("0 ");
}
else
solve(*it,k),k=0;
}
}puts("");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:44: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:46: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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |