QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#606624 | #8932. Bingo | Kanate# | WA | 24ms | 3712kb | C++14 | 2.3kb | 2024-10-03 11:03:24 | 2024-10-03 11:03:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rint int
#define endl '\n'
#define uint unsigned long long
void debug(int *a,int n){for(rint i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl;}
void debug(int *a){for(rint i=1;a[i];i++) cout<<a[i]<<" ";cout<<endl;}
void debug(int x){cout<<"debug: "<<x<<endl;}
int read(){
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))x=x*10+c-48,c=getchar();
return x*f;
}const int N=2e5+10,p=1e9,mod=998244353;
int n,m,mm;
char s[N],g[15];
char ans[N],res[N];
bool cmp()
{
if(!ans[1]) return 1;
if(res[0]==49) return 0;
for(rint i=1;i<=n;i++)
if(ans[i]<res[i]) return 0;
else if(ans[i]>res[i]) return 1;
return 0;
}
bool check(int x)
{
for(rint i=x;i<=x+m-1;i++)
if(s[i]>g[i-x+1]) return 0;
else if(s[i]<g[i-x+1]) return 1;
return 0;
}
void work2(int x)
{
for(rint i=1;i<x;i++) res[i]=s[i];
for(rint i=x;i<=x+m-1;i++) res[i]=g[i-x+1];
for(rint i=x+m;i<=n;i++) res[i]='0';
if(cmp())
for(rint i=1;i<=n;i++) ans[i]=res[i];
}
void baoli()
{
int nn=0;
for(rint i=1;i<=n;i++)
nn=nn*10+s[i]-48;
if(nn<mm) return cout<<mm<<endl,void();
for(rint i=n-m+1;i>0&&i>=n-m+1-20;i--)
if(check(i)) work2(i);
int yu=nn%mm;
yu=mm-yu;
int val=nn+yu;
// cout<<"val "<<val<<endl;
if(ans[1])
{
int aas=0;
for(rint i=1;i<=n;i++)
aas=aas*10+ans[i]-48;
val=min(val,aas);
}
cout<<val<<endl;
}
void work(int yu)
{
for(rint i=n;~i;i--)
{
int x=s[i]-48+yu%10;yu/=10;
if(x>9) yu++,x-=10;
res[i]=x+48;
}
if(cmp())
for(rint i=0;i<=n;i++) ans[i]=res[i];
}
void Work()
{
ans[1]=0,mm=0,s[0]='0';
scanf("%s",s+1),n=strlen(s+1);ans[n+1]=0;
scanf("%s",g+1),m=strlen(g+1);
for(rint i=1;i<=m;i++) mm=mm*10+g[i]-48;
if(n<=17) return baoli(),void();
for(rint i=n-m+1;i>0&&i>=n-m+1-20;i--)
if(check(i)) work2(i);
int yu=0;
for(rint i=1;i<=n;i++)
yu=(yu*10+s[i]-48)%mm;
yu=mm-yu;
work(yu);
if(ans[0]==49) putchar('1'),ans[0]=0;
printf("%s\n",ans+1);
}
signed main()
{
#ifndef ONLINE_JUDGE
// freopen("1.in", "r", stdin);
// freopen("1.out", "w", stdout);
#else
#endif
// int T=1;
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: 1ms
memory: 3712kb
input:
6 7 3 12 3 9 10 249 51 1369 37 2 1
output:
9 13 10 251 1370 3
result:
ok 6 lines
Test #2:
score: -100
Wrong Answer
time: 24ms
memory: 3664kb
input:
100000 3196282243 28 7614814237 33 2814581084 97 1075124401 58 7822266214 100 1767317768 31 7189709841 75 9061337538 69 6552679231 38 9946082148 18 5497675062 54 7787300351 65 4310767261 68 4811341953 100 3265496130 31 8294404054 62 2845521744 90 1114254672 26 6442013672 13 3744046866 40 3289624367 ...
output:
3196282264 7614814251 2814581097 1075124424 7822266300 1767317781 7189709850 9061337569 6552679238 9946082160 5497675092 7787300365 4310767268 4811342000 3265496131 8294404062 2845521790 1114254674 6442013682 3744046880 3289624375 6477935360 1292587551 5504674689 2898829180 7882736025 2846033387 923...
result:
wrong answer 1st lines differ - expected: '3196282244', found: '3196282264'