# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1096369 | slah007 | Weird Numeral System (CCO21_day1problem2) | C++17 | 0 ms | 344 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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> chk;
bool go(long long n){
if(n > 2e18) assert(false);
if(chk.count(n)) return 0;
chk[n] = 1;
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 1;
}
}
}
return 0;
}
int main(){
scanf("%d %d %d %d", &K, &Q, &D, &M);
assert(D<=MAXD);
for(int i=0;i<D;i++) scanf("%d", arr+i);
while(Q--){
long long n;
scanf("%lld", &n);
chk.clear();
if(!go(n)){
printf("IMPOSSIBLE");
}
puts("");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |