QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#411852 | #3791. Interesting Calculator | 23lpx | 100 ✓ | 74ms | 5356kb | C++20 | 1.3kb | 2024-05-15 20:41:36 | 2024-05-15 20:41:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
struct PII{
int sum,cnt;
}dp[N];
PII mmin(PII A,PII B)
{
if(A.sum==B.sum)
{
return A.cnt<B.cnt?A:B;
}
return A.sum<B.sum?A:B;
}
int cost[100][100];
signed main()
{
int x,y,idx=1;
PII t;
while(~scanf("%lld%lld",&x,&y))
{
for(int i=0;i<3;i++)
{
for(int j=0;j<10;j++)
{
scanf("%lld",&cost[j][i]);
}
}
memset(dp,0x3f,sizeof dp);
dp[0].cnt=1;dp[0].sum=cost[0][2];
dp[x].cnt=dp[x].sum=0;
for(int i=1;i<=y;i++)
{
t.sum=dp[i/10].sum+cost[i%10][0];
t.cnt=dp[i/10].cnt+1;
dp[i]=mmin(dp[i],t);
for(int j=1;j<10;j++)
{
if(i-j>=0)
{
t.sum=dp[i-j].sum+cost[j][1];
t.cnt=dp[i-j].cnt+1;
dp[i]=mmin(dp[i],t);
}
if(i%j==0)
{
t.sum=dp[i/j].sum+cost[j][2];
t.cnt=dp[i/j].cnt+1;
dp[i]=mmin(dp[i],t);
}
}
}
printf("Case %lld: %lld %lld\n",idx++,dp[y].sum,dp[y].cnt);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 74ms
memory: 5356kb
input:
12 256 100 100 100 1 100 100 100 100 100 100 6 5 4 3 2 1 2 3 4 5 100 100 10 100 100 100 100 100 100 100 12 256 100 100 100 1 100 100 100 100 100 100 100 100 100 100 100 1 100 100 100 100 100 100 10 100 100 100 100 100 100 100 1 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 10...
output:
Case 1: 9 4 Case 2: 12 3 Case 3: 500000 5 Case 4: 49999 49999 Case 5: 700000 7 Case 6: 68382 10 Case 7: 112558 11 Case 8: 130701 18 Case 9: 63820 10 Case 10: 225950 7 Case 11: 198287 11 Case 12: 123217 19 Case 13: 91914 10 Case 14: 137984 11 Case 15: 85481 22 Case 16: 180261 12 Case 17: 26654 9 Case...
result:
ok 30 lines