QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#605313#8932. BingoYeyin_0WA 0ms3716kbC++142.5kb2024-10-02 16:40:062024-10-02 16:40:08

Judging History

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

  • [2024-10-02 16:40:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3716kb
  • [2024-10-02 16:40:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define fo(i,a,b) for(long long i=(a);i<=(b);i++)
#define fe(i,a,b) for(long long i=(a);i>=(b);i--)
const int N=1000010;
LL m,mod;
LL Ans;
string a;
struct gjd
{
    LL len;
    LL num[N];
    void Clear()
    {
        fo(i,0,len-1) num[i]=0;
        len=0;
    }
    void add(LL x)
    {
        x=(x+m*m)%m;
        fo(i,0,len-1)
        {
            num[i]=num[i]+x%10;
            x/=10;
            if(num[i]>=10)
            {
                num[i]-=10;
                x++;
            }
        }
        while(x)
        {
            len++;
            num[len-1]=x;
            x/=10;
        }
    } 
    void replace(LL x)
    {
        LL u=0,cnt=x;
        bool bb=0;
        while(cnt)
        {
            u++;
            cnt/=10;
        }
        fo(i,u-1,len-1)
        {
            LL p=0;
            fo(j,0,u-1)
            {
                p=p*10+num[i-j];
            }
            if(p==x&&bb)
            {
                Ans=1;
                return;
            }
            if(num[i-u+1]!=9) bb=1;
        }
        LL wei=1,ppp=1;
        fo(i,u-1,len-1)
        {
            LL p=0;
            fo(j,0,u-1)
            {
                p=p*10+num[i-j];
            }
            if(p<x&&ppp==1)
            {
                Ans=min(Ans,x-p);
            }
            else if(p<x&&ppp<=1e15)
            {
                Ans=min(Ans,ppp*(x-p-1)+wei);
            }
            else if(p==x-1&&ppp>=1e15)
            {
                Ans=min(Ans,wei);
            }
            if(ppp<=1e15)
            {
                wei=wei+(LL)(9-num[i-u+1])*ppp; 
                ppp*=10;
            } 
            else if(num[i-u+1]!=9) return;
            if(wei>Ans) return;
        }
    }
    void bui()
    {
        len=a.size();
        fo(i,0,a.size()-1)
        {
            num[len-i-1]=a[i]-'0';
        }
    }
    void output()
    {
        fe(i,len-1,0) cout<<num[i];
        cout<<endl;
    }
} A,B;

void read(){
    A.Clear();
    B.Clear();
    cin>>a>>m;
    mod=0;
    fo(i,0,a.size()-1)
    {
        mod=mod*10+(LL)a[i]-(LL)'0';
        mod%=m;
    }
    A.bui();
    B.bui();
    if(mod%m!=0) Ans=(m-mod%m+m)%m;
    else Ans=m;
    B.replace(m);
    A.add(Ans);
    A.output();
}
void solve()
{
    read();
}
int main()
{
    int tcase;
    cin>>tcase;
    while(tcase--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3716kb

input:

6
7 3
12 3
9 10
249 51
1369 37
2 1

output:

9
13
10
251
1370
2

result:

wrong answer 6th lines differ - expected: '3', found: '2'