//8 out of 25 marks - no overflows possible
#include <bits/stdc++.h>
#define int long long int
signed main() {
int K, Q, D, M;
std::cin >> K >> Q >> D >> M;
std::set<int> digits;
for (int i = 0; i < D; ++i) {
int a;
std::cin >> a;
digits.insert(a);
}
for (int _ = 0; _ < Q; ++_) {
int number;
std::cin >> number;
int power = 1;
std::stack<int> result;
while (number) {
int next = (number % (power * K)) / power;
next = (next + std::abs(next) * K) % K;
int digit = 0;
if (digits.count(next)) {
digit = next;
} else if (digits.count(next - K)) {
digit = next - K;
} else {
goto broken;
}
result.push(digit);
number -= digit * power;
power *= K;
}
while (!result.empty()) {
std::cout << result.top() << " ";
result.pop();
}
std::cout << std::endl;
continue;
broken:
std::cout << "IMPOSSIBLE" << std::endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Query 1: Jury has an answer but participant does not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Query 1: Jury has an answer but participant does not |
2 |
Halted |
0 ms |
0 KB |
- |