QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#649014 | #8932. Bingo | 11d10xy | WA | 41ms | 3808kb | C++14 | 1.7kb | 2024-10-17 21:16:59 | 2024-10-17 21:17:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m;
char str[1000010];
inline bool cmp(string x,string y){
if(x.size()==y.size())return x<y;
return x.size()<y.size();
}
inline void prints(string s){
for(char c:s)putchar(c);puts("");
}
void solve(){
scanf("%s%d",str+1,&m),n=strlen(str+1);
int p0=n;
while(str[p0]=='9')p0--;
if(!p0){
n++,str[1]='1';for(int i=2;i<=n;i++)str[i]='0';str[n+1]='\0';
}else{
str[p0]++;for(int i=p0+1;i<=n;i++)str[i]='0';
}
if(n<9||(n==9&&str[1]=='1')){
int x;sscanf(str+1,"%d",&x);
if(x<=m)return printf("%d\n",m),void();
}
char mstr[12]{};
sprintf(mstr,"%d",m);int o=strlen(mstr);
for(int i=1;i+o-1<=n;i++)if(equal(str+i,str+i+o,mstr)){
printf("%s\n",str+1);
return;
}
string ans0(str+1);
int val=0;
for(int i=1;i<=n;i++)val=(val*10+str[i])%m;
val=(m-val)%m;
reverse(begin(ans0),end(ans0));
for(int i=0;val;i++){
if(i==ans0.size())ans0+='0';
val+=ans0[i]-'0';
ans0[i]=val%10+'0',val/=10;
}
int p=max(n-20,1);
string lst;
for(int i=n;i>=n-10&&i>=o;i--){
string w(str+p,str+n+1);
bool flag=true;
for(int k=0;k<o;k++){
if(mstr[k]<str[i-o+1+k]){flag=false;break;}
if(mstr[k]>str[i-o+1+k])break;
}
if(flag){
for(int k=0;k<o;k++)
w[w.size()-1-(n-(i-o+1+k))]=mstr[k];
if(lst.empty()||lst>w)lst=w;
}
}
if(lst.empty())prints(ans0);
else{
string ans2(str+1,str+p);
ans2+=lst;
prints(min(ans0,ans2,cmp));
}
}
int main(){
int T;for(scanf("%d",&T);T--;)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3808kb
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: 41ms
memory: 3808kb
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:
3196282244 1524184167 2814581097 1075124458 2726622287 1767317769 7189709875 9061337569 4329762556 6612806499 5497675063 2040037877 4310767268 2791431184 3265496131 2014044928 2671255482 1114264673 6442013673 3744046867 2244269823 8535397746 0657852921 5504674689 2519288982 2206372887 2846033387 841...
result:
wrong answer 2nd lines differ - expected: '7614814251', found: '1524184167'