# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1102502 | nathan4690 | Weird Numeral System (CCO21_day1problem2) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define el cout << '\n'
#define f1(i,n) for(int i=1;i<=n;i++)
#define __file_name ""
using namespace std;
const ll maxn = 1e6+5, inf=1e18;
int k,q,d,m,a[maxn];
ll n;
vector<ll> mp[maxn], ans;
unordered_map<ll, bool> flag;
bool check(ll n){
if(flag.find(n) != flag.end()) return false;
flag[n] = true;
ll v = (n % k + k) % k;
for(int item: mp[v]){
if(item == n){
ans.push_back(item);
return 1;
}else if(check((n - item) / k)){
ans.push_back(item);
return 1;
}
}
return 0;
}