QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#268852#6300. Best Carry Player 2wbjjjjjWA 0ms3968kbC++142.0kb2023-11-28 22:17:192023-11-28 22:17:19

Judging History

你现在查看的是最新测评结果

  • [2023-11-28 22:17:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3968kb
  • [2023-11-28 22:17:19]
  • 提交

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

*/

详细

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'