Submission #1096372

#TimeUsernameProblemLanguageResultExecution timeMemory
1096372slah007Weird Numeral System (CCO21_day1problem2)C++17
0 / 25
529 ms1048576 KiB
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cassert>
#include <map>
using namespace std;

const int MAXK = 1e6;
const int MAXM = 2500;
const int MAXD = MAXM<<1|1;

int K, Q, D, M;
int arr[MAXK];

map<long long, int> dp;
bool go(long long n){
    if(n > 2e18) assert(false);
    if(dp.count(n)) return dp[n];
    for(int i=0;i<D;i++){
        if((n-arr[i])%K == 0){
            long long t = (n-arr[i])/K;
            if(t == 0 || go(t)){
                printf("%d ", arr[i]);
                return dp[n] = 1;
            }
        }
    }
    return 0;
}

int main(){
    scanf("%d %d %d %d", &K, &Q, &D, &M);
    if(D>5001){
        while(1)puts("?");
    }
    for(int i=0;i<D;i++) scanf("%d", arr+i);
    while(Q--){
        long long n;
        scanf("%lld", &n);
        dp.clear();
        if(!go(n)){
            printf("IMPOSSIBLE");
        }
        puts("");
    }
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'bool go(long long int)':
Main.cpp:25:30: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   25 |                 return dp[n] = 1;
Main.cpp: In function 'int main()':
Main.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d %d %d %d", &K, &Q, &D, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:37:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     for(int i=0;i<D;i++) scanf("%d", arr+i);
      |                          ~~~~~^~~~~~~~~~~~~
Main.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         scanf("%lld", &n);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...