# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
446653 | RGBB | Weird Numeral System (CCO21_day1problem2) | C++14 | 977 ms | 1180 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int MAXD=5005;
int k,q,d,m,coef[MAXD];
vector<int>outp;
unordered_map<ll,bool>memo;
bool solve(ll v){
if(memo.find(v)!=memo.end())return memo[v];
memo[v]=false;
for(int i=0;i<d;i++){
if(v==coef[i]){
outp.push_back(coef[i]);
return memo[v]=true;
}
if((v-coef[i])%k!=0)continue;
if((v-coef[i])/k!=v&&solve((v-coef[i])/k)){
outp.push_back(coef[i]);
return memo[v]=true;
}
}
return memo[v];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>k>>q>>d>>m;
for(int i=0;i<d;i++)cin>>coef[i];
for(int i=0;i<q;i++){
ll inp;
cin>>inp;
outp.clear();
memo.clear();
if(solve(inp)){
for(int j=0;j<outp.size()-1;j++)cout<<outp[j]<<" ";
cout<<outp.back()<<"\n";
}
else cout<<"IMPOSSIBLE\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |