이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <queue>
#include <map>
using namespace std;
map<long long int, int> m;
vector<int> g[1000005], res;
int k;
bool trya(long long int x) {
if (m.count(x)) return false;
long long int h = (x % k + k) % k;
m[x] = 0;
for (int w : g[h]) {
if (x == w) {
res.push_back(w);
return true;
}
if ((x - w) / k != x && trya((x - w) / k)) {
res.push_back(w);
return true;
}
}
return false;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(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;
m.clear();
res.clear();
y = trya(x);
if (y == 0) {
cout << "IMPOSSIBLE" << '\n';
continue;
}
for (int w : res) cout << w << " ";
cout << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |