답안 #1102394

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102394 2024-10-18T04:00:02 Z adaawf Weird Numeral System (CCO21_day1problem2) C++17
0 / 25
5 ms 23888 KB
#include <iostream>
#include <queue>
#include <unordered_map>
using namespace std;
unordered_map<long long int, int> m;
vector<int> g[1000005];
int k;
int trya(long long int x) {
    if (x == 0) return 0;
    if (m.count(x)) return m[x];
    long long int res = -1e9, h = (x % k + k) % k;
    for (int w : g[h]) {
        if ((x - w) / k == x) continue;
        int l = trya((x - w) / k);
        if (l != -1e9) {
            res = w;
            break;
        }
    }
    m[x] = res;
    return res;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    m[0] = 0;
    long long int q, d, ma;
    cin >> k >> q >> d >> ma;
    for (int i = 1; i <= d; i++) {
        long long int x, y;
        cin >> x;
        y = (x % k + k) % k;
        g[y].push_back(x);
    }
    for (int jj = 0; jj < q; jj++) {
        long long int x, y;
        cin >> x;
        y = trya(x);
        if (y == -1e9) {
            cout << "IMPOSSIBLE" << '\n';
            continue;
        }
        vector<int> v;
        while (x) {
            v.push_back(m[x]);
            x = (x - m[x]) / k;
        }
        for (int i = v.size() - 1; i >= 0; i--) {
            cout << v[i] << " \n"[i+1==(int)v.size()];
        }
        cout << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 23888 KB For n=453315765336943587, representation is not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 23888 KB For n=453315765336943587, representation is not correct
2 Halted 0 ms 0 KB -