# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1102396 | adaawf | Weird Numeral System (CCO21_day1problem2) | C++17 | 1092 ms | 25224 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <queue>
#include <map>
using namespace std;
#define int long long
map<int, int> m;
vector<int> g[1000005], res;
int k;
bool trya(int x) {
if (m.count(x)) return false;
int h = (x % k + k) % k;
m[x] = 0;
for (int i = 0; i < g[h].size(); i++) {
int w = g[h][i];
if (x == w) {
res.push_back(w);
return true;
}
if ((x - w) / k != x && trya((x - w) / k)) {
res.push_back(w);
return true;
}
}
return false;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int q, d, ma;
cin >> k >> q >> d >> ma;
for (int i = 1; i <= d; i++) {
int x, y;
cin >> x;
y = (x % k + k) % k;
g[y].push_back(x);
}
for (int jj = 0; jj < q; jj++) {
int x, y;
cin >> x;
m.clear();
res.clear();
y = trya(x);
if (y == 0) {
cout << "IMPOSSIBLE" << '\n';
continue;
}
for (int i = 0; i < res.size(); i++) cout << res[i] << " \n"[i+1==(int)res.size()];
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |