Submission #13537430
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
long long A, B, C, D;
long long INF = 5e18;
void min_self(long long& a, long long b) {
a = min(a, b);
}
map<long long, long long> mapka;
long long f(long long goal) {
if(goal == 0) {
return 0;
}
if(goal == 1) {
return D;
}
if(mapka.count(goal)) {
return mapka[goal];
}
long long best = INF;
if(D < INF / goal) {
min_self(best, D * goal);
}
for(int i = 0; i < 3; ++i) {
int mul = vector<int>{2,3,5}[i];
long long cost = vector<long long>{A,B,C}[i];
if(goal % mul == 0) {
min_self(best, cost + f(goal / mul));
}
else {
long long down = goal / mul * mul;
min_self(best, cost + D * (goal - down) + f(goal / mul));
long long up = down + mul;
min_self(best, cost + D * (up - goal) + f(goal / mul + 1));
}
}
return mapka[goal] = best;
}
void test_case() {
long long N;
cin >> N;
cin >> A >> B >> C >> D;
cout << f(N) << endl;
mapka.clear();
}
int main() {
int T;
cin >> T;
while(T--) {
test_case();
}
}
Submission Info
| Submission Time |
|
| Task |
A - Pay to Win |
| User |
Errichto |
| Language |
C++ (GCC 9.2.1) |
| Score |
400 |
| Code Size |
1905 Byte |
| Status |
AC |
| Exec Time |
108 ms |
| Memory |
4500 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example0.txt |
| All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, example0.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 000.txt |
AC |
2 ms |
3588 KiB |
| 001.txt |
AC |
2 ms |
3444 KiB |
| 002.txt |
AC |
2 ms |
3436 KiB |
| 003.txt |
AC |
2 ms |
3444 KiB |
| 004.txt |
AC |
2 ms |
3568 KiB |
| 005.txt |
AC |
108 ms |
4500 KiB |
| 006.txt |
AC |
72 ms |
4044 KiB |
| 007.txt |
AC |
83 ms |
4248 KiB |
| 008.txt |
AC |
73 ms |
4016 KiB |
| example0.txt |
AC |
24 ms |
4236 KiB |