QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#268852 | #6300. Best Carry Player 2 | wbjjjjj | WA | 0ms | 3968kb | C++14 | 2.0kb | 2023-11-28 22:17:19 | 2023-11-28 22:17:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int t,k,len,cnt;
string a;
int num[25];
int ans;
void pre()
{
for(int i=len;i>=1;--i)
{
int j=i-1;
while(a[j]=='9')
{
j--;
if(j==0) break;
}
num[i]=i-j;
}
}
ll change(int anss)
{
ll chan = 0;
int judge=0;
for(int i=0;i<len;++i)
{
if((anss & (1<<i)) != 0)
{
chan += (10-(a[len-i]-'0')-judge)*pow(10,i);
judge=1;
}
else judge=0;
}
return chan;
}
void dfs(int now, int tot, int now_ans, bool judge) // now是当前位置,tot是进位数
{
if(now<0 || tot>k) return;
// if(now_ans&1)
// cout<<now<<' '<<tot<<' '<<now_ans<<endl;
if(tot==k)
{
ans=min(ans,now_ans);
return;
}
if(now==0) return;
dfs(now-1,tot,now_ans,0);
if(a[now]=='0' && judge==0) return;
int now_ans2=now_ans;
// for(int i=now-num[now]+1;i<=now;++i)
// {
// now_ans2 |= (1<<(len-i));
// }
now_ans2 |= (1<<(len-now));
dfs(now-num[now],tot+num[now],now_ans2,1);
return;
}
int main()
{
cin>>t;
while(t--)
{
string str;
cin>>str>>k;
a="0"+str;
len = str.length();
pre();
if(k==0)
{
int cnt1=len;
while(a[cnt1]=='9')
{
cnt1--;
}
cout << pow(10,len-cnt1) << endl;
// system("pause");
continue;
}
ans = (1<<20)-1;
dfs(len,0,0,0);
// for(int i=0;i<len;++i)
// {
// if((ans&(1<<i))!=0) cout << len-i<<endl;
// }
ll real_ans = change(ans);
for(int i=1;i<=k-len;++i)
{
real_ans += 9*pow(10,len+i-1);
}
cout<<real_ans<<endl;
}
// system("pause");
return 0;
}
/*
1
990099 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3968kb
input:
4 12345678 0 12345678 5 12345678 18 990099 5
output:
1 54322 999999999987655552 9910
result:
wrong answer 3rd lines differ - expected: '999999999987654322', found: '999999999987655552'