답안 #732717

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
732717 2023-04-29T07:55:27 Z loctildore Weird Numeral System (CCO21_day1problem2) C++17
0 / 25
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(x) begin(x), end(x)
int k, q, d, m;
int a;
map<int, bool> done;
vector<int> vctr, ans;
bool dp(int x, bool top = false) {
    if (!x && !top) return true;
    if (done[x]) return false;
    done[x] = true;
    for (auto i : vctr) if ((x - i) % k == 0) {
        if (dp((x - i) / k)) {
            ans.push_back(i);
            return true;
        }
    }
    return false;
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cin>>k>>q>>d>>m;
    for (int i = 0; i < d; i++) {
        cin>>a;
        vctr.push_back(a);
    }
    for (int i = 0; i < q; i++) {
        done.clear();
        ans.clear();
        cin>>a;
        if (dp(a, true)) {
            for (auto j : ans) cout<<j<<' ';
            cout<<endl;
        }
        else cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "IMPOSSIBLE" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Expected integer, but "IMPOSSIBLE" found
2 Halted 0 ms 0 KB -