QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#268844 | #6300. Best Carry Player 2 | wbjjjjj | WA | 1ms | 3480kb | C++14 | 1.7kb | 2023-11-28 22:07:39 | 2023-11-28 22:07:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int t,k,len;
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;
}
}
string change(int anss)
{
string chan = "";
int judge=0;
for(int i=0;i<len;++i)
{
if((anss & (1<<i)) != 0)
{
chan = (char)((10-(a[len-i]-'0')-judge)+'0')+chan;
judge=1;
}
else
{
chan = "0"+chan;
judge=0;
}
}
int cnt=0;
while(chan[cnt]=='0')
{
cnt++;
}
chan = chan.substr(cnt,chan.length()-cnt);
return chan;
}
void dfs(int now, int tot, int now_ans, bool judge) // now是当前位置,tot是进位数
{
if(now<0 || tot>k) return;
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;
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();
ans = (1<<20)-1;
dfs(len,0,0,0);
string real_ans = change(ans);
if(real_ans=="") real_ans="1";
for(int i=1;i<=k-len;++i)
{
real_ans = "9"+real_ans;
}
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: 100
Accepted
time: 1ms
memory: 3376kb
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: 1ms
memory: 3480kb
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:
1 10000 1000 100 10 1 :00001 9:00001 99:00001 999:00001 10000000001 9999910000 9999:01000 9999:00100 9999:00010 9999:00001 99999900001 999999900001 9999999900001 89999999999999999: 1
result:
wrong answer 1st lines differ - expected: '100000', found: '1'