답안 #554458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
554458 2022-04-28T12:33:03 Z loctildore Weird Numeral System (CCO21_day1problem2) C++14
0 / 25
0 ms 212 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;
ll qs[69];
ll arr[5069];
vector<ll> ans;
unordered_map<ll,ll> track;
stack<ll> sk;
bool find(ll x) {
  if (-m<=x&&x<=m) {
    if (track.find(x)==track.end()) {
      return 0;
    }
    if (x!=track[x]) {
      ll cur=(x-track[x])/k;
      find(cur);
    }
    ans.push_back(track[x]);
    return 1;
  }
  for (int i = 0; i < d; i++) {
    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];
    track[arr[i]]=arr[i];
    sk.push(arr[i]);
  }
  while (sk.size()) {
    ll tmp=sk.top();
    sk.pop();
    for (int i = 0; i < d; i++) {
      ll cur=tmp*k+arr[i];
      if (cur<-m||cur>m) {
        continue;
      }
      if (track.find(cur)==track.end()) {
        track[cur]=arr[i];
        sk.push(cur);
      }
    }
  }
  for (int i = 0; i < q; i++) {
    cin>>qs[i];
  }
  for (int i = 0; i < q; i++) {
    cout<<qs[i]<<' ';
  }
  cout<<q<<"wtf"<<endl;
  /*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"<<endl;
    }
  }*/
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Expected int32, but "773746700847275732" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Expected int32, but "773746700847275732" found
2 Halted 0 ms 0 KB -