답안 #507653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
507653 2022-01-12T22:42:05 Z ETK Weird Numeral System (CCO21_day1problem2) C++14
0 / 25
1 ms 204 KB
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define ALL(x) x.begin(),x.end()
#define sz(x) int(x.size())
#define ll long long
using namespace std;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    return x*f;
}
const int N=5005;
int K,q,D,M,a[N];
unordered_map <ll,bool> mp;
vector <int> ans;
bool dp(ll x){
    if(mp.find(x) != mp.end())return mp[x];
    mp[x] = 0;
    rep(i,1,D){
        if(x == a[i]){
            ans.pb(a[i]);
            return mp[x] = 1;
        }
        if((x-a[i]) % K == 0){
            if( (x-a[i]) / K != x && dp((x - a[i]) / K)){
                ans.pb(a[i]);
                return mp[x] = 1;
            }
        }
    }
    return mp[x];
}
int main(){
    K = read(),q = read(),D = read(),M = read();
    rep(i,1,D){
        a[i] = read();
    }
    while(q--){
        ll x = read();
        ans.clear();
        mp.clear();
        if(dp(x)){
            rep(i,0,sz(ans)-1)printf("%d ",ans[i]);
            puts("");
        }else puts("IMPOSSIBLE");
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Expected integer, but "IMPOSSIBLE" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Expected integer, but "IMPOSSIBLE" found
2 Halted 0 ms 0 KB -