Submission #732436

# Submission time Handle Problem Language Result Execution time Memory
732436 2023-04-29T04:19:58 Z Programmer123 Weird Numeral System (CCO21_day1problem2) C++17
0 / 25
1 ms 212 KB
//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 -