Submission #413283

# Submission time Handle Problem Language Result Execution time Memory
413283 2021-05-28T12:34:06 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 zero[802], one[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(zero[rem]){
        vec.push_back(rem);
        solve((x-rem)/k);
        if(printed) return;
        vec.pop_back();
    }

    if(one[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) zero[x]++;
        if(x < 0) one[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:26: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   46 |         if(x >= 0) zero[x]++;
      |                    ~~~~~~^
Main.cpp:47:26: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   47 |         if(x < 0) one[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);
      |         ~~~~~^~~~~~~~~~~~~~~