QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#293001#6300. Best Carry Player 2zxzxzxq#WA 0ms3640kbC++171.4kb2023-12-28 19:30:212023-12-28 19:30:22

Judging History

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

  • [2023-12-28 19:30:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3640kb
  • [2023-12-28 19:30:21]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

using i64 = long long ;
using i128 = __int128;

const int N = 1e5 + 10;

i64 n, k;
i128 pw[40];
string s;

i128 calc()
{
    i128 res = 0;
    for(i128 i = 0;i < s.size();i ++)
        res = res * 10 + (s[i] - '0');
    return res;
}

void print(i128 x)
{
    if (x  < 0)
    {
        putchar('-');
        x = -x;
    }
    if (x > 9)
        print(x / 10);
    putchar('0' +( x % 10));
}

void solve()
{
    cin >> s >> k;

    n = calc();

    reverse(s.begin(), s.end());
    if (k == 0) 
    {
        for(int i = 0;i < s.size();i ++)
            if(s[i] != '9')
            {
                print(pw[i]);
                puts("");
                return ;
            }
        print(pw[s.size()]);
        puts("");
        return ;
    }

    
    for(i128 i = 0;i < s.size();i ++)
    {
        i64 st = i + k;
        if (st != s.size() && s[st] == '9'|| s[i] == '0') continue;
        i128 aim = n % pw[st] / pw[i];
        i128 ans = pw[st] - aim * pw[i];
        print(ans);
        puts("");
        return ;
    }

    puts("-1");
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    pw[0] = 1;
    for(i128 i = 1;i < 40;i ++)
        pw[i] = pw[i - 1] * 10;

    int T = 1;
    cin >> T;
    while(T --)
        solve();

    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

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

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
99999000010000000000
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
99999999999999999900000000000000000
1000000000000000000

result:

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