QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#242871#6300. Best Carry Player 2neonahtWA 1ms3680kbC++171.7kb2023-11-07 17:56:502023-11-07 17:56:50

Judging History

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

  • [2023-11-07 17:56:50]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3680kb
  • [2023-11-07 17:56:50]
  • 提交

answer

#include <bits/stdc++.h>
#define DEBUG 0
#define CASES 1
#define st first
#define nd second
#define ll long long
using namespace std;
typedef double db;
const int SZ = 2e5 + 7;
const int MX = 1e9 + 7;
const int MOD = 1e9 + 7;
const long long MX2 = 1e18 + 1;

long long dp[20][20][2];

void process(void) {
    string x, y;
    int k;
    cin >> y >> k;
    int you = 18-y.size();
    for(int i=0; i<you; i++) x.push_back('0');
    x += y;

    for(int i=0; i<20; i++) {
        for(int j=0; j<20; j++) {
            if(j>0) dp[i][j][0] = MX2;
            dp[i][j][1] = MX2;
        }
    }

    if(x[x.size()-1] != '0') dp[x.size()-1][1][1] = 10 - (x[x.size()-1] - 48);

    for(int i=x.size()-2; i>-1; i--) {
        for(int j=1; j<=k; j++) {
            long long add0 = (pow(10,(x.size()-1-i)))*(10-(x[i]-48));
            long long add1 = (pow(10,(x.size()-1-i)))*(9-(x[i]-48));
            dp[i][j][1] = dp[i+1][j-1][1] + add1;
            if(x[i] != '0') dp[i][j][1] = min(dp[i][j][1] ,dp[i+1][j-1][0] + add0);
            dp[i][j][0] = dp[i+1][j][0];
            if(x[i] != '9') dp[i][j][0] = min(dp[i][j][0], dp[i+1][j][1]);
        }
    }

    long long res = min(dp[0][k][0], dp[0][k][1]);

    if(!k) {
        int idx = 17, cnt = 0;
        while(idx>-1 && x[idx] == '9') {
            ++cnt;
            --idx;
        }
        cout << '1';
        for(int i=0; i<cnt; i++) cout << '0';
    }
    else cout << (res == MX2 ? -1 : res);
    cout << '\n';

    return ;
}
 
int main() {
    #ifndef DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    cin.tie(nullptr)->ios::sync_with_stdio(false);
    int t(1);
    if(CASES) cin >> t;
    while(t--) process();
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3680kb

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
54322
999999999987655576
9910

result:

wrong answer 3rd lines differ - expected: '999999999987654322', found: '999999999987655576'