#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 time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
OK |
2 |
Correct |
1 ms |
320 KB |
OK |
3 |
Correct |
1 ms |
212 KB |
OK |
4 |
Correct |
1 ms |
212 KB |
OK |
5 |
Correct |
1 ms |
212 KB |
OK |
6 |
Correct |
1 ms |
212 KB |
OK |
7 |
Correct |
1 ms |
340 KB |
OK |
8 |
Correct |
0 ms |
340 KB |
OK |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
OK |
2 |
Correct |
1 ms |
320 KB |
OK |
3 |
Correct |
1 ms |
212 KB |
OK |
4 |
Correct |
1 ms |
212 KB |
OK |
5 |
Correct |
1 ms |
212 KB |
OK |
6 |
Correct |
1 ms |
212 KB |
OK |
7 |
Correct |
1 ms |
340 KB |
OK |
8 |
Correct |
0 ms |
340 KB |
OK |
9 |
Correct |
11 ms |
1440 KB |
OK |
10 |
Correct |
5 ms |
724 KB |
OK |
11 |
Correct |
3 ms |
468 KB |
OK |
12 |
Correct |
3 ms |
340 KB |
OK |
13 |
Correct |
98 ms |
1936 KB |
OK |
14 |
Correct |
30 ms |
952 KB |
OK |
15 |
Correct |
11 ms |
468 KB |
OK |
16 |
Correct |
0 ms |
212 KB |
OK |
17 |
Correct |
1 ms |
320 KB |
OK |
18 |
Correct |
1158 ms |
2024 KB |
OK |
19 |
Correct |
1890 ms |
1936 KB |
OK |
20 |
Correct |
0 ms |
212 KB |
OK |
21 |
Correct |
87 ms |
1556 KB |
OK |
22 |
Correct |
525 ms |
1544 KB |
OK |
23 |
Correct |
749 ms |
1616 KB |
OK |
24 |
Correct |
547 ms |
1608 KB |
OK |
25 |
Correct |
668 ms |
1912 KB |
OK |
26 |
Correct |
795 ms |
2008 KB |
OK |
27 |
Correct |
0 ms |
212 KB |
OK |
28 |
Correct |
1 ms |
212 KB |
OK |