QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#358785 | #6300. Best Carry Player 2 | Djangle162857 | WA | 0ms | 3692kb | C++20 | 1.1kb | 2024-03-20 00:17:20 | 2024-03-20 00:17:21 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=25;
int t,K,L;
int a10[N];
int s,k;
int a[N];
int dp[N][N];
signed main() {
a10[0]=1;
for(int i=1;i<18;i++) a10[i]=a10[i-1]*10;
cin>>t;
while(t--) {//补充一个特判
cin>>s>>k;
L=0;
for(int i=0;i<18;i++) {
a[i]=s%10;
if(a[i]) L=i;
s/=10;
}
if(a[0]==9) {
int tt=0;
while(a[tt]==9) tt++;
if(tt==k) {
cout<<1<<endl;
continue;
}
}
L=max(L,k-1);
for(int i=0;i<=18;i++)
for(int j=1;j<=18;j++) dp[i][j]=-1;
//dp[0][0]=0;
if(a[0]) dp[0][1]=10-a[0];
for(int i=1;i<=L;i++) {
if(a[i]) dp[i][1]=a10[i]*(10-a[i]);
for(int j=2;j<=i+1;j++) {
if(a[i]>0) {
for(int j1=0;j1<=i-2;j1++) {
if((a[j1]+a[j1+1]!=18)&&~dp[j1][j-1])
dp[i][j]=dp[j1][j-1];
}
}
if(~dp[i-1][j-1])
dp[i][j]=dp[i-1][j-1]+a10[i]*(9-a[i]);
}
}
int ans=0;
for(int i=0;i<18;i++) {
if(~dp[i][k]&&a[i]+a[i+1]!=18) {
if(dp[i][k]==0) dp[i][k]++;
cout<<dp[i][k]<<endl;ans=1;
break;
}
}
if(!ans) cout<<-1<<endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3692kb
input:
4 12345678 0 12345678 5 12345678 18 990099 5
output:
1 54322 999999999987654322 9910
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3660kb
input:
21 999990000099999 0 999990000099999 1 999990000099999 2 999990000099999 3 999990000099999 4 999990000099999 5 999990000099999 6 999990000099999 7 999990000099999 8 999990000099999 9 999990000099999 10 999990000099999 11 999990000099999 12 999990000099999 13 999990000099999 14 999990000099999 15 999...
output:
1 10000 1000 100 10 1 900001 9900001 99900001 999900001 9999900001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 -1 1
result:
wrong answer 1st lines differ - expected: '100000', found: '1'