이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |