QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#744490#6300. Best Carry Player 2tea#WA 35ms3596kbC++172.7kb2024-11-13 22:07:082024-11-13 22:07:09

Judging History

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

  • [2024-11-13 22:07:09]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:3596kb
  • [2024-11-13 22:07:08]
  • 提交

answer

// #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define pb push_back
#define st first
#define nd second
#define PII pair<ll, ll>
#define D(x, y) cout << x << "=" << y << endl;
#define fcout(x, n) cout << fixed << setprecision(x) << n << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
// #define int long long
typedef long long ll;
typedef unsigned long long ull;
const ll inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
const int M = 1e9+7;
ll n,m;
ll a[20];
ll mpow(ll x,ll y)
{
    ll s=1;
    rep(i,0,y) s*=x; 
    return s;
}
void solve()
{
    memset(a,0,sizeof(a));
    string s;cin>>s;
    ll l=s.length();
    rep(i,1,l+1) a[i]=s[l-i]-48;
    ll k;cin>>k;
    if(k==0) //k=0
    {
        ll x=1;
        while(a[x]==9) x++;
        cout<<1;
        rep(i,0,x-1) cout<<0;
        cout<<endl;
        return;
    }    
    ll s0=0,x=1;
    while(a[x]==0) x++,s0++;
    if(l-x+1<=k||a[k+x]!=9) //k比位数长 || 正常后k位
    {
        ll t=0;
        if(l-x+1<=k)
        {
            rep2(i,l,x) t=t*10+a[i];
        }
        else if(a[x+k]!=9)
        {
            rep2(i,k+x-1,x) t=t*10+a[i];
        }
        cout<<mpow(10,k)-t;
        rep(i,0,s0) cout<<0;
        cout<<endl;
        return;
    }
    ll x9=k+x,s9=0;
    while(a[x9+1]==9&&x9<=l-1) x9++;
    rep2(i,x9,x)
    {
        if(a[i]==9) s9++;
        else break;
    }
    if(a[x9-k+1]!=0) //最前面k位
    {
        ll t=0;
        rep2(i,x9,x9-k+1) t=t*10+a[i];
        cout<<mpow(10,k)-t;
        rep(i,0,x9-k+s0) cout<<0;
        cout<<endl;
        return;
    }
    if(s9>=k) //前导9长度大于k
    {
        cout<<1;
        rep(i,0,x9-k) cout<<0;
        cout<<endl;
        return;
    }
    // 前导9长小于k 分段
    ll xx9=x9-k+1;
    while(a[xx9]==0) xx9++;
    ll t=0;
    ll l1=x9-xx9+1,l2=k-l1;
    rep2(i,x9,xx9) t=t*10+a[i];
    cout<<mpow(10,l1)-t;
    rep(i,0,x9-x+1-k) cout<<0;
    t=0;
    rep2(i,x+l2-1,x) t=t*10+a[i];
    ll st=0,tt=mpow(10,l2)-t;
    while(tt!=0) tt/=10,st++;
    rep(i,0,l2-st) cout<<0;
    cout<<mpow(10,l2)-t;
    rep(i,0,s0) cout<<0;
    cout<<endl;
    return;
}
signed main()
{
    IOS
        // freopen("../.vscode/io/in.txt","r",stdin),freopen("../.vscode/io/out.txt","w",stdout);
        ll T = 1;
    cin >> T;
    while (T--)
        solve();
}
/*
5
1234999 0
323000 2
123000 6
990099 5
990009 5
*/

/*
11
99301093 1
99301093 2
99301093 3
99301093 4
99301093 5
99301093 6
99301093 7
99301093 8
99301093 9
99301093 10
99301093 18
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
54322
999999999987654322
9910

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3596kb

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
1000000000000000000

result:

ok 21 lines

Test #3:

score: -100
Wrong Answer
time: 35ms
memory: 3460kb

input:

100000
119111011091190000 10
1911011191011999 16
110099199000119 0
19009911191091011 13
199090909919000900 17
19009010011919110 5
90910190019900091 18
10911100000101111 1
110090011101119990 4
100909999119090000 12
90901119109011100 2
111010119991090101 4
900991019109199009 5
100919919990991119 8
911...

output:

88988908810000
8088988808988001
10
88808908989
9800909090080999100
80890
909089809980099909
9
80010
9090000880910000
8900
9909
991
9008900
8880880090
8080090801
8009900808909899
80880898981
909
8800909
99988889901
89908888089
980908890980099000
1000
9889801
81
908890008099900891
880990801
9998099
89...

result:

wrong answer 24th lines differ - expected: '100', found: '1000'