QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#303557 | #6300. Best Carry Player 2 | ucup-team052# | WA | 0ms | 3788kb | C++23 | 1.7kb | 2024-01-12 18:34:07 | 2024-01-12 18:34:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define mod 998244353
#define int __int128
#define inf 0x3f3f3f3f
#define INF ((int)1e19)
inline int read()
{
char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
if(nega==-1) return -ans;
return ans;
}
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
int pw[105];
void work()
{
int n=read(),k=read();
vector<int> s;
while(n)
{
s.push_back(n%10);
n/=10;
}
while((int)s.size()<36) s.push_back(0);
int mn=0;
if(k==0)
{
int pw=1;
for(int i=0;;i++)
{
if(s[i]!=9)
{
printf("%lld\n",(long long)pw);
return ;
}
pw*=10;
}
}
vector<int> ts=s;
int tk=k;
for(int i=0;k>0;i++)
{
// if(s[i]==9)
{
int j=i;
while(s[j+1]==9) j++;
int gv=min(j-i+1,j-i+1);
mn+=(10-s[j-gv+1])*pw[j-gv+1];
s[j+1]++;
i=j;
k-=gv;
}
// else
// {
// k--;
// mn+=(10-s[i])*pw[i];
// s[i+1]++;
// }
}
int adi=-k;
s=ts,k=tk;
int ans=0;
for(int i=0;k>0;i++)
{
// if(s[i]==9)
{
int j=i;
while(s[j+1]==9) j++;
int ngo=min(adi,j-i+1);
adi-=ngo;
int gv=j-i+1-ngo;
if(gv) ans+=(10-s[j-gv+1])*pw[j-gv+1];
s[j+1]++;
i=j;
k-=gv;
}
// else
// {
// k--;
// mn+=(10-s[i])*pw[i];
// s[i+1]++;
// }
}
printf("%lld\n",(long long)ans);
}
signed main()
{
pw[0]=1; for(int i=1;i<=19;i++) pw[i]=pw[i-1]*10;
int T=read(); while(T--) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3724kb
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: 3788kb
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 9999900000 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 900000000000000000 1000000000000000000
result:
wrong answer 11th lines differ - expected: '10000000001', found: '9999900000'