Submission #1102503

#TimeUsernameProblemLanguageResultExecution timeMemory
1102503BuzzyBeezWeird Numeral System (CCO21_day1problem2)C++17
0 / 25
1 ms592 KiB
#include <bits/stdc++.h> using namespace std; map<long long, pair<int, int>> dp[1008]; int a[5008]; int d, K; int attempt(int n, long long R) { if (n > 1000) return 1; if (dp[n].count(R)) return dp[n][R].first; if (R == 0) { dp[n][R] = make_pair(2, 0); return 2; } for (int i = 1; i <= d; ++i) if ((R - a[i]) % K == 0) { if (attempt(n + 1, (R - a[i]) / K) == 2) { dp[n][R] = make_pair(2, a[i]); return 2; } } dp[n][R] = make_pair(1, 0); return 1; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q, m; cin >> K >> q >> d >> m; for (int i = 1; i <= d; ++i) cin >> a[i]; long long N; bool pass; while (q--) { cin >> N; pass = 0; for (int i = 1; i <= d; ++i) if (attempt(0, N) == 2) {pass = 1; break;} if (!pass) cout << "IMPOSSIBLE\n"; else { vector<int> ans; // for (int i = 0; N; ++i) { // ans.push_back(dp[i][N].second); // N = (N - dp[i][N].second) / K; // } // reverse(ans.begin(), ans.end()); // for (int i : ans) cout << i << ' '; // cout << '\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...