답안 #732436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
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;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Query 1: Jury has an answer but participant does not
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Query 1: Jury has an answer but participant does not
2 Halted 0 ms 0 KB -