# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
413285 | 2021-05-28T12:36:35 Z | 반딧불(#7606) | Weird Numeral System (CCO21_day1problem2) | C++17 | 905 ms | 1048580 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int k, q, d, m; bool arr0[802], arr1[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(arr0[rem]){ vec.push_back(rem); solve((x-rem)/k); if(printed) return; vec.pop_back(); } if(arr1[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) arr0[x] = 1; if(x < 0) arr1[x+k] = 1; } while(q--){ ll g; scanf("%lld", &g); printed = 0; vec.clear(); solve(g); if(!printed) printf("IMPOSSIBLE\n"); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 905 ms | 1048580 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 905 ms | 1048580 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |