Submission #554279

# Submission time Handle Problem Language Result Execution time Memory
554279 2022-04-28T06:09:17 Z loctildore Weird Numeral System (CCO21_day1problem2) C++14
0 / 25
829 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define endl '\n'
#define all(x) begin(x), end(x)
ll k,q,d,m,n;
vector<ll> ans;
ll arr[5069];
bool find(ll x) {
  for (int i = 0; i < d; i++) {
    if (arr[i]==x) {
      ans.push_back(arr[i]);
      return true;
    }
    if ((x-arr[i])%k==0) {
      if (find((x-arr[i])/k)) {
        ans.push_back(arr[i]);
        return true;
      }
    }
  }
  return false;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin>>k>>q>>d>>m;
  for (int i = 0; i < d; i++) {
    cin>>arr[i];
  }
  for (int t = 0; t < q; t++) {
    ans.clear();
    cin>>n;
    if (find(n)) {
      for (auto i : ans) {
        cout<<i<<' ';
      }
      cout<<endl;
    }
    else {
      cout<<"IMPOSSIBLE";
    }
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 829 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 829 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -