QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#744780 | #6300. Best Carry Player 2 | tea | WA | 1ms | 3844kb | C++17 | 2.5kb | 2024-11-13 23:18:40 | 2024-11-13 23:18:40 |
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 a[20],ans[N];
ll cnt;
bool bb=0;
ll mpow(ll x,ll y)
{
ll s=1;
rep(i,0,y) s*=x;
return s;
}
void as(ll l,ll k)
{
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;
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;
return;
}
if(s9>=k) //前导9长度大于k
{
cout<<1;
rep(i,0,x9-k) cout<<0;
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;
while(a[--xx9]==0) cout<<0;
bb=1;
as(xx9,l2);
}
void solve()
{
cnt=0;bb=0;
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;
}
as(l,k);
cout<<endl;
}
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: 1ms
memory: 3844kb
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: 3612kb
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 1000001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 1000000000000000000
result:
wrong answer 11th lines differ - expected: '10000000001', found: '1000001'