Submission #576314

#TimeUsernameProblemLanguageResultExecution timeMemory
576314eecsWeird Numeral System (CCO21_day1problem2)C++17
25 / 25
1890 ms2024 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0), cin.tie(0); int K, q, d; cin >> K >> q >> d >> *new int; vector<int> a(d); for (int &x : a) cin >> x; unordered_set<ll> f[80]; while (q--) { ll n; cin >> n; f[0] = {n}; bool flag = 0; for (int i = 1; i < 80; i++) { f[i].clear(); for (ll x : f[i - 1]) { for (int y : a) if (!((x - y) % K)) { f[i].insert((x - y) / K); } } if (f[i].count(0)) { for (ll x = 0; i; i--) { for (int y : a) if (f[i - 1].count(x * K + y)) { cout << y << " \n"[i == 1]; x = x * K + y; break; } } flag = 1; break; } } if (!flag) cout << "IMPOSSIBLE\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...