답안 #446651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446651 2021-07-22T22:37:43 Z RGBB Weird Numeral System (CCO21_day1problem2) C++14
0 / 25
3 ms 460 KB
#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];
    for(int i=0;i<d;i++){
        if(v!=coef[i]&&(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]=false;
}
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();
        memo[0]=true;
        if(solve(inp)){
            for(int j=0;j<outp.size()-1;j++)cout<<outp[j]<<" ";
            cout<<outp.back()<<"\n";
        }
        else cout<<"IMPOSSIBLE\n";
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |             for(int j=0;j<outp.size()-1;j++)cout<<outp[j]<<" ";
      |                         ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB OK
2 Runtime error 3 ms 460 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB OK
2 Runtime error 3 ms 460 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -