제출 #60720

#제출 시각아이디문제언어결과실행 시간메모리
60720alenam0161Zalmoxis (BOI18_zalmoxis)C++17
0 / 100
379 ms10832 KiB
#include <bits/stdc++.h>
using namespace std;
const int N  = 1000000+7;
int a[N];
int main(){
 
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;++i){
        scanf("%d",a+i);
    }
    stack<int> st;
    st.push(a[0]);
    vector<int> ans;
    ans.push_back(a[0]);
    for(int i=1;i<n;++i){
        if(a[i]>=st.top()){
            while(a[i]>=st.top()){
                int x=st.top();
                ans.push_back(x);
                st.pop();
                st.push(x+1);
                while(st.size()>=2){
                    int z=st.top();
                    st.pop();
                    if(z==st.top()){
                        st.pop();
                        st.push(z+1);
                    }
                    else{
                        st.push(z);
                        break;
                    }
                }
                k--;
            }

            k++;
        }
        else{
            ans.push_back(a[i]);
            st.push(a[i]);
        }
    }
    while(st.size()>1){
        int x=st.top();
        st.pop();
        int y=st.top();
        while(x<=y){
            ans.push_back(x);
            x++;
            k--;
        }
        st.pop();
        st.push(x);
        k++;
    }
    int z=st.top();
    while(k>0){
        ans.push_back(z);
        z++;
        k--;
    }
    for(int i=0;i<ans.size();++i){
        printf("%d ",a[i]);
    }
    printf("\n");
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:64:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<ans.size();++i){
                 ~^~~~~~~~~~~
zalmoxis.cpp:8: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:10:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",a+i);
         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...