Submission #413326

#TimeUsernameProblemLanguageResultExecution timeMemory
413326sebinkimWeird Numeral System (CCO21_day1problem2)C++17
0 / 25
15 ms24012 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; map<ll, ll> M; queue<ll> Q; vector<ll> A[1010101]; ll k, q, d, m; void tc(ll n) { ll t, u; M.clear(); for (; !Q.empty(); Q.pop()); if (n) Q.push(n); else { for (ll &a: A[0]) { u = -a / k; M[u] = 0; Q.push(u); } } for (; !Q.empty(); ) { t = Q.front(); Q.pop(); if (t == 0) { for (; t != n; t = M[t]) { cout << (M[t] - t * k) << " "; } cout << "\n"; return; } for (ll &a: A[(t % k + k) % k]) { u = (t - a) / k; if (M.find(u) == M.end()) { M[u] = t; Q.push(u); } } } cout << "IMPOSSIBLE\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); ll i, t, n; cin >> k >> q >> d >> m; for (i = 0; i < d; i++) { cin >> t; A[(t % k + k) % k].push_back(t); } for (; q--; ) { cin >> n; tc(n); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...