답안 #578608

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578608 2022-06-17T11:16:51 Z FatihSolak Zalmoxis (BOI18_zalmoxis) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define N 200005
using namespace std;
vector<int> create(int a,int b){
    if(b == 1){
        return {a};
    }
    auto l = create(a-1,b/2);
    auto r = create(a-1,b-b/2);
    for(auto u:r){
        l.push_back(u);
    }
    return l;
}
void solve(){
    int n,k;
    cin >> n >> k;
    vector<pair<int,int>> v;
    vector<int> now = {30};
    for(int i = 1;i<=n;i++){
        int x;
        cin >> x;
        while(now.back() < x){
            v.push_back({now.back(),1});
            now.pop_back();
        }
        while(now.back() > x){
            int tmp = now.back()-1;
            now.pop_back();
            now.push_back(tmp);
            now.push_back(tmp);
        }
        v.push_back({now.back(),0});
        now.pop_back();
    }
    while(now.size())
        v.push_back({now.back(),1});
        now.pop_back();
    }
    vector<int> ans;
    int needed = n + k -  v.size();
    for(auto u:v){
        auto tmp = create(u.first,(u.second?min(1<<u.first,needed+1):1));
        for(auto c:tmp){
            ans.push_back(c);
        }
        needed -= tmp.size() - 1;
    }
    assert(ans.size() == n + k);
    for(auto u:ans){
        cout << u << " ";
    }
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    #ifdef Local
    cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Compilation message

zalmoxis.cpp: In function 'void solve()':
zalmoxis.cpp:36:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   36 |     while(now.size())
      |     ^~~~~
zalmoxis.cpp:38:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   38 |         now.pop_back();
      |         ^~~
zalmoxis.cpp: At global scope:
zalmoxis.cpp:41:18: error: 'n' was not declared in this scope; did you mean 'yn'?
   41 |     int needed = n + k -  v.size();
      |                  ^
      |                  yn
zalmoxis.cpp:41:22: error: 'k' was not declared in this scope
   41 |     int needed = n + k -  v.size();
      |                      ^
zalmoxis.cpp:41:27: error: 'v' was not declared in this scope
   41 |     int needed = n + k -  v.size();
      |                           ^
zalmoxis.cpp:42:5: error: expected unqualified-id before 'for'
   42 |     for(auto u:v){
      |     ^~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from zalmoxis.cpp:1:
zalmoxis.cpp:49:5: error: expected unqualified-id before 'static_cast'
   49 |     assert(ans.size() == n + k);
      |     ^~~~~~
zalmoxis.cpp:49:5: error: expected ')' before 'static_cast'
zalmoxis.cpp:50:5: error: expected unqualified-id before 'for'
   50 |     for(auto u:ans){
      |     ^~~
zalmoxis.cpp:53:1: error: expected declaration before '}' token
   53 | }
      | ^