QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#744942 | #6300. Best Carry Player 2 | tea | WA | 0ms | 3592kb | C++17 | 2.3kb | 2024-11-14 00:31:03 | 2024-11-14 00:31:03 |
Judging History
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[20];
char ans[20];
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 pt(ll l,ll r)
{
rep(i,l,n+1)
if(!ans[i]) ans[i]='0';
while(ans[l]=='0') l++;
puts(ans+l);
}
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;
pt(l,r);
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;
}
pt(l,r);
}
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();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
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: 3592kb
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 1000000000000000000 10000 1000 100 10 1 900001 9900001 99900001 999900001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000
result:
wrong answer 2nd lines differ - expected: '10000', found: '1000000000000000000'