QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#279968 | #6300. Best Carry Player 2 | forget-star# | WA | 1ms | 5720kb | C++14 | 1.9kb | 2023-12-09 13:04:49 | 2023-12-09 13:04:50 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
//#include <windows.h>
#define ll long long
#define i128 __int128
using namespace std;
int read()
{
int a = 0,x = 1;char ch = getchar();
while(ch > '9' && ch < '0'){if(ch == '-') x = -1;ch = getchar();}
while(ch >= '0' && ch <= '9'){a = a*10 + ch-'0';ch = getchar();}
return a*x;
}
const int N=1e6+7;
i128 f[45][45][2],o[45];
char s[N];
int arr[N],K,len,g[N];
void print(i128 p)
{
if(p > 9) print(p/10);
putchar('0'+p%10);
}
void solve()
{
scanf("%s %d",s+1,&K);len = strlen(s+1);memset(f,63,sizeof(f));
for(int i = 0;i <= 37;i ++) arr[i] = g[i] = 0;
// printf("###\n");
f[0][0][0] = 0;
reverse(s+1,s+1+len);for(int i = 1;i <= len;i ++) arr[i] = s[i]-'0';
if(K == 0) {
for(int i = 1;i <= len;i ++) if(arr[i] != 9) {
print(o[i-1]);puts("");return ;
}
}
for(int i = 37;i >= 1;i --) g[i] = (arr[i] == 9) ? g[i+1] + 1:1;
for(int i = 0;i <= 37;i ++) for(int j = 0;j <= K;j ++) {
for(int k = 0;k <= 1;k ++) {
//if(f[i][j][k] < f[0][0][1]) {printf("f[%d][%d:%d][%d] = ",i,j,K,k);print(f[i][j][k]);puts("");}
if(j == K && f[i][j][k] < f[0][0][1]) {
// printf("i%d j%d k%d\n",i,j,k);
print(f[i][j][k]);puts("");return ;
}
f[i+1][j][0] = min(f[i+1][j][0],f[i][j][k]);
if(k == 0 && arr[i+1] == 0) continue;
f[i+g[i+2]][j+g[i+2]][1] = min(f[i+g[i+2]][j+g[i+2]][1],f[i][j][k] + o[i] * (10-arr[i+1]-k));
}
}
}
int main()
{
// freopen("in.in","r",stdin);
int T = read();o[0] = 1;
for(int i = 1;i <= 36;i ++) o[i] = o[i-1]*10;
//for(int i = 4;i <= 7;i ++) for(int j = 4;j <= 7;j ++) solve(i,j);
while(T --) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5720kb
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: 1ms
memory: 5608kb
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:
100000 10000 1000 100 10 1 900001 9900001 99900001 999900001 10000000001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 0
result:
wrong answer 21st lines differ - expected: '1000000000000000000', found: '0'