Submission #732720

#TimeUsernameProblemLanguageResultExecution timeMemory
732720loctildoreWeird Numeral System (CCO21_day1problem2)C++14
25 / 25
1761 ms1680 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(x) begin(x), end(x)
int k, q, d, m;
int a;
map<int, bool> done;
vector<int> vctr, ans;
bool dp(int x, bool top = false) {
    if (!x && !top) return true;
    if (done[x]) return false;
    done[x] = true;
    for (auto i : vctr) if ((x - i) % k == 0) {
        if (dp((x - i) / k)) {
            ans.push_back(i);
            return true;
        }
    }
    return false;
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cin>>k>>q>>d>>m;
    for (int i = 0; i < d; i++) {
        cin>>a;
        vctr.push_back(a);
    }
    for (int i = 0; i < q; i++) {
        done.clear();
        ans.clear();
        cin>>a;
        if (dp(a, true)) {
            for (int j = 0; j < ans.size(); j++) {
                cout<<ans[j];
                if (j != ans.size() - 1) cout<<' ';
            }
            cout<<endl;
        }
        else cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:37:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             for (int j = 0; j < ans.size(); j++) {
      |                             ~~^~~~~~~~~~~~
Main.cpp:39:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |                 if (j != ans.size() - 1) cout<<' ';
      |                     ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...