답안 #60746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60746 2018-07-24T15:53:46 Z alenam0161 Zalmoxis (BOI18_zalmoxis) C++17
0 / 100
106 ms 50520 KB
#include <bits/stdc++.h>
void fl();
using namespace std;
const int N  = 1000000+7;
int a[N];
stack<int> st;
vector<int> ans;
void rem(){
    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;
        }
    }
}
int main(){
    fl();
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;++i){
        scanf("%d",a+i);
    }
    st.push(a[0]);
    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.push(x);
                rem();
                k--;
            }
            ans.push_back(a[i]);
            st.push(a[i]);
            rem();
        }
        else{
            ans.push_back(a[i]);
            st.push(a[i]);
        }
    }
    while(st.size()!=1){
        ans.push_back(st.top());
        st.push(st.top());
        rem();
        k--;
    }
    int z=st.top();
    while(k>0){
        ans.push_back(z);
        z++;
        k--;
    }
    if(ans.size()!=k+n){
        assert(0);
    }
    for(int i=0;i<ans.size();++i){
        printf("%d ",ans[i]);
    }
    return 0;
}
void fl(){
    freopen("input.txt","r",stdin);
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:61:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(ans.size()!=k+n){
        ~~~~~~~~~~^~~~~
zalmoxis.cpp:64:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<ans.size();++i){
                 ~^~~~~~~~~~~
zalmoxis.cpp:25: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:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",a+i);
         ~~~~~^~~~~~~~~~
zalmoxis.cpp: In function 'void fl()':
zalmoxis.cpp:70:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("input.txt","r",stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 82 ms 33696 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 86 ms 50076 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 94 ms 50324 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 83 ms 50324 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 80 ms 50324 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 106 ms 50448 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 88 ms 50448 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 95 ms 50448 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 100 ms 50448 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 95 ms 50500 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 88 ms 50500 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 94 ms 50500 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 91 ms 50500 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 91 ms 50500 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 104 ms 50500 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 84 ms 50500 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 81 ms 50520 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 80 ms 50520 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 91 ms 50520 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 90 ms 50520 KB Execution killed with signal 11 (could be triggered by violating memory limits)