# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1102497 | nathan4690 | Weird Numeral System (CCO21_day1problem2) | C++14 | 5 ms | 25168 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define el cout << '\n'
#define f1(i,n) for(int i=1;i<=n;i++)
#define __file_name ""
using namespace std;
const ll maxn = 1e6+5, inf=1e18;
int k,q,d,m,a[maxn];
ll n;
vector<ll> mp[maxn], ans;
unordered_map<ll, bool> flag;
bool check(ll n){
if(flag.find(n) != flag.end()) return false;
flag[n] = true;
ll v = (n % k + k) % k;
for(int item: mp[v]){
if(item == n){
ans.push_back(item);
return 1;
}else if(check((n - item) / k)){
ans.push_back(item);
return 1;
}
}
return 0;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if(fopen(__file_name ".inp", "r")){
freopen(__file_name ".inp","r",stdin);
freopen(__file_name ".out","w",stdout);
}
// code here
cin >> k >> q >> d >> m;
f1(i,d) {
cin >> a[i];
mp[(a[i] % k + k) % k].push_back(a[i]);
}
while(q--){
cin >> n;
flag.clear();
ans.clear();
if(check(n)){
// reverse(ans.begin(), ans.end());
for(ll item: ans) cout << item << ' ';
el;
}else cout << "IMPOSSIBLE\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |