Contest Duration: - (local time) (150 minutes) Back to Home

Submission #19364951

Source Code Expand

Copy
```#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod (int)(1e9+7)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 500005

int n, a, b, c, d;

int MEM(int cur, map<int,int> &dp)
{
//cout << cur << endl;
if(cur==0)
return 0;

if(cur==1)
return d;

if(dp.count(cur))
return dp.at(cur);

int ans = (int)(1e18);

if(cur <= ans/d)
ans = min(ans, cur*d);

if(cur%2==0)
ans = min(ans, a + MEM(cur/2, dp));
else
{
ans = min(ans, a + (cur%2)*d + MEM((cur-cur%2)/2, dp));
ans = min(ans, a + (2-cur%2)*d + MEM((cur+2-cur%2)/2, dp));
}

if(cur%3==0)
ans = min(ans, b + MEM(cur/3, dp));
else
{
ans = min(ans, b + (cur%3)*d + MEM((cur-cur%3)/3, dp));
ans = min(ans, b + (3-cur%3)*d + MEM((cur+3-cur%3)/3, dp));
}

if(cur%5==0)
ans = min(ans, c + MEM(cur/5, dp));
else
{
ans = min(ans, c + (cur%5)*d + MEM((cur-cur%5)/5, dp));
ans = min(ans, c + (5-cur%5)*d + MEM((cur+5-cur%5)/5, dp));
}

dp[cur] = ans;
return ans;
}

int32_t main()
{

int t;
cin >> t;
while(t--)
{

cin >> n >> a >> b >> c >> d;
map<int, int> dp;
cout << MEM(n, dp) << endl;
}

return 0;
}

```

#### Submission Info

Submission Time 2021-01-11 02:19:22+0900 A - Pay to Win pawan_asipu C++ (GCC 9.2.1) 400 1425 Byte AC 105 ms 4356 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
 AC × 1
 AC × 10
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 9 ms 3416 KB
001.txt AC 2 ms 3384 KB
002.txt AC 2 ms 3460 KB
003.txt AC 3 ms 3512 KB
004.txt AC 3 ms 3444 KB
005.txt AC 105 ms 4316 KB
006.txt AC 69 ms 4144 KB
007.txt AC 80 ms 4184 KB
008.txt AC 72 ms 4016 KB
example0.txt AC 22 ms 4356 KB