#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;
while (q--) {
ll n;
cin >> n;
array<unordered_set<ll>, 80> f;
f[0].insert(n);
bool flag = 0;
for (int i = 1; i < 80; i++) {
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 time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
OK |
2 |
Correct |
1 ms |
212 KB |
OK |
3 |
Correct |
1 ms |
212 KB |
OK |
4 |
Correct |
1 ms |
316 KB |
OK |
5 |
Correct |
1 ms |
212 KB |
OK |
6 |
Correct |
1 ms |
212 KB |
OK |
7 |
Correct |
1 ms |
212 KB |
OK |
8 |
Correct |
1 ms |
320 KB |
OK |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
OK |
2 |
Correct |
1 ms |
212 KB |
OK |
3 |
Correct |
1 ms |
212 KB |
OK |
4 |
Correct |
1 ms |
316 KB |
OK |
5 |
Correct |
1 ms |
212 KB |
OK |
6 |
Correct |
1 ms |
212 KB |
OK |
7 |
Correct |
1 ms |
212 KB |
OK |
8 |
Correct |
1 ms |
320 KB |
OK |
9 |
Correct |
14 ms |
1552 KB |
OK |
10 |
Correct |
6 ms |
724 KB |
OK |
11 |
Correct |
2 ms |
468 KB |
OK |
12 |
Correct |
3 ms |
448 KB |
OK |
13 |
Correct |
104 ms |
1908 KB |
OK |
14 |
Correct |
33 ms |
824 KB |
OK |
15 |
Correct |
11 ms |
468 KB |
OK |
16 |
Correct |
0 ms |
212 KB |
OK |
17 |
Correct |
0 ms |
212 KB |
OK |
18 |
Correct |
1146 ms |
2016 KB |
OK |
19 |
Correct |
1901 ms |
2048 KB |
OK |
20 |
Correct |
1 ms |
212 KB |
OK |
21 |
Correct |
86 ms |
1532 KB |
OK |
22 |
Correct |
529 ms |
1724 KB |
OK |
23 |
Correct |
750 ms |
1616 KB |
OK |
24 |
Correct |
545 ms |
1608 KB |
OK |
25 |
Correct |
669 ms |
1908 KB |
OK |
26 |
Correct |
796 ms |
2000 KB |
OK |
27 |
Correct |
0 ms |
212 KB |
OK |
28 |
Correct |
0 ms |
212 KB |
OK |