Submission #413284

# Submission time Handle Problem Language Result Execution time Memory
413284 2021-05-28T12:35:22 Z 반딧불(#7606) Weird Numeral System (CCO21_day1problem2) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int k, q, d, m;
bool a0[802], a1[802];

bool printed;
vector<int> vec;

void solve(ll x){
    if(x==0){
        for(int i=(int)vec.size()-1; i>=0; i--){
            printf("%d ", vec[i]);
        }
        puts("");
        printed = 1;
        return;
    }
    ll rem;
    if(x>=0) rem = x%k;
    else rem = (k - (-x)%k) % k;

    if(a0[rem]){
        vec.push_back(rem);
        solve((x-rem)/k);
        if(printed) return;
        vec.pop_back();
    }

    if(a1[rem]){
        vec.push_back(rem-k);
        solve((x-rem)/k+1);
        if(printed) return;
        vec.pop_back();
    }
}

int main(){
    scanf("%d %d %d %d", &k, &q, &d, &m);
    for(int i=1; i<=d; i++){
        int x;
        scanf("%d", &x);
        if(x >= 0) a0[x]++;
        if(x < 0) a1[x+k]++;
    }

    while(q--){
        ll goal;
        scanf("%lld", &goal);
        printed = 0;
        vec.clear();
        solve(goal);
        if(!printed) printf("IMPOSSIBLE\n");
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:46:24: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   46 |         if(x >= 0) a0[x]++;
      |                    ~~~~^
Main.cpp:47:25: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   47 |         if(x < 0) a1[x+k]++;
      |                   ~~~~~~^
Main.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d %d %d %d", &k, &q, &d, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
Main.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         scanf("%lld", &goal);
      |         ~~~~~^~~~~~~~~~~~~~~