QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#279965#6300. Best Carry Player 2forget-star#WA 1ms3788kbC++141.8kb2023-12-09 13:02:512023-12-09 13:02:53

Judging History

你现在查看的是最新测评结果

  • [2023-12-09 13:02:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3788kb
  • [2023-12-09 13:02:51]
  • 提交

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 ;
            }
            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));
            f[i+1][j][0] = min(f[i+1][j][0],f[i][j][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: 3788kb

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: 3788kb

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
10999910000
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
0

result:

wrong answer 11th lines differ - expected: '10000000001', found: '10999910000'