# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
413289 | 2021-05-28T12:52:32 Z | 송준혁(#7515) | Weird Numeral System (CCO21_day1problem2) | C++17 | 1 ms | 204 KB |
#include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define Mup(a,x) a=max(a, x) #define mup(a,x) a=min(a, x) #define all(v) v.begin(),v.end() #define lb lower_bound #define INF (1ll<<60) #define MOD 1'000'000'007 using namespace std; typedef long long LL; typedef pair<int,int> pii; LL N; int K, Q, M; int A[5050], P[110]; vector<pii> D[110]; int main(){ scanf("%d %d %d %*d", &K, &Q, &M); for (int i=1; i<=M; i++) scanf("%d", &A[i]); D[0].pb(pii(0,0)); while (Q--){ scanf("%lld", &N); int i; for (i=1; i<=64; i++){ D[i].clear(); int pv=MOD; P[i] = (N%K+K)%K; bool tf = false; for (pii t : D[i-1]){ if (t.fi == pv) continue; if (t.fi == N && i > 1){ tf = true; break; } for (int j=1; j<=M; j++) if (((t.fi+A[j])%K+K)%K == P[i]){ D[i].pb(pii((t.fi+A[j]-P[i])/K, t.fi)); } pv = t.fi; } if (tf) break; sort(all(D[i])); N = (N-P[i])/K; } pii pv = pii(MOD,0); i--; for (pii t : D[i]) if (t.fi == N) pv = t; if (pv.fi == MOD){ puts("IMPOSSIBLE"); continue; } for (i--; i>=0; i--){ for (int j=1; j<=M; j++){ if ((pv.se+A[j]-((pv.se+A[j])%K+K)%K)/K == pv.fi && ((pv.se+A[j])%K+K)%K == P[i+1]){ printf("%d ", A[j]); break; } } for (pii t : D[i]) if (t.fi == pv.se){ pv = t; break; } } printf("\n"); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Expected integer, but "IMPOSSIBLE" found |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Expected integer, but "IMPOSSIBLE" found |
2 | Halted | 0 ms | 0 KB | - |