QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#744948#6300. Best Carry Player 2teaWA 0ms3756kbC++202.6kb2024-11-14 00:36:252024-11-14 00:36:25

Judging History

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

  • [2024-11-14 00:36:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3756kb
  • [2024-11-14 00:36:25]
  • 提交

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 k;
ll jw[25];
char ans[25];
string s;
void zh(ll l,ll r)
{
	ans[r]='9'-s[r]+'0'+1,k--;
    rep(i,l,r) ans[i]='9'-s[i]+'0',k--;
	if(l>1&&ans[l-1]>'0') ans[l-1]--;
}
void solve()
{
    memset(ans,0,sizeof(ans));
    cin>>s;s=" "+s;
    n=s.length()-1;
    cin>>k;
    if(k==0) //k=0
    {
        bool b=0;
        rep2(i,n,1)
        {
            if(s[i]^'9')
            {
                cout<<jw[n-i]<<endl;
                b=1;break;
            }
        }
        if(!b) cout<<jw[n]<<endl;
        return;
    }
    ll r=n;while(s[r]=='0') r--;
    ll l=r-k+1;//cout<<"l:"<<l<<" "<<r<<endl;
    if(l<1) //前k
    {
        rep(i,r+1,n+1) ans[i]='0';
        zh(1,r);
        //rep(i,1,r+1) cout<<ans[i];cout<<endl;
        while(k--) putchar('9');
        puts(ans+1);
        return;
    }
    if(l==1||s[l-1]^'9') //后k
    {
        zh(l,r);//rep(i,1,r+1) cout<<ans[i];cout<<endl;
        rep(i,l,n+1)
            if(!ans[i]) ans[i]='0';
        while(ans[l]=='0') l++;
        puts(ans+l);
        return;
    }
    while(l>1&&s[l-1]=='9') l--;
    while(k) //分段
    {
        ll x=r-k+1;
        if(s[x-1]^'9') 
        {
            zh(x,r);//rep(i,1,r+1) cout<<ans[i];cout<<endl;
            return;
        }
        while(s[x-1]=='9') x--;
            ll y=x+k-1;
            while(s[y]=='0') y--;
            if(x>y) return;
            zh(x,y),x=y;
    }
	rep(i,l,n+1) if(!ans[i]) ans[i]='0';
	while(ans[l]=='0') l++;
	puts(ans+l);
}
signed main()
{
    //IOS
        // freopen("../.vscode/io/in.txt","r",stdin),freopen("../.vscode/io/out.txt","w",stdout);
        ll T = 1;
    cin >> T;

    jw[0]=1;for(int i=1;i<20;i++) jw[i]=jw[i-1]*10;
    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
*/

詳細信息

Test #1:

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

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

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

result:

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