QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#572623 | #8932. Bingo | ucup-team073# | WA | 103ms | 7696kb | C++20 | 2.1kb | 2024-09-18 15:39:19 | 2024-09-18 15:39:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e6 + 155;
int a[maxn], m, len, dt, b[20],c[maxn];
__int128 Q[30];
char s[maxn], t[maxn];
void solve(){
cin>>s>>m;
len = strlen(s);
int Res = 0;
for(int i=0;i<=len+100;++i)a[i]=c[i]=0;
for(int i = 1; i <= len; ++i){
Res = (Res * 10 + (s[i-1] ^ 48)) % m;
a[len-i]=s[i-1]-'0';
}
a[0]++;
for(int i=0;i<len;++i)if(a[i]>=10)a[i]-=10,a[i+1]++;
if(a[len])++len;
//for(int i=0;i<len;++i)cout<<a[i]<<' ';cout<<endl;
int tmp=m,cnt=0,flag=0;
while(tmp)b[cnt++]=tmp%10,tmp/=10;
for(int i=cnt;i<=len;++i){
int F=1;
for(int j=i-cnt;j<i;++j)if(a[j]!=b[j-(i-cnt)])F=0;
if(F)flag=1;
}
if(flag){
for(int i=len-1;i>=0;--i)cout<<a[i];cout<<'\n';
return;
}
__int128 sum=0,S=m,res=m-Res;
flag=0;
for(int i=0;i<cnt;++i)sum=sum+a[i]*Q[i];
for(int i=cnt;i<cnt*2;++i){
__int128 ans=S-sum;
if(i==cnt&&ans>=0)flag=ans;
//cout<<(int)S<<' '<<(int)sum<<'\n';
if(ans<0)ans+=Q[i];
res=min(res,ans+1);
sum=sum+a[i]*Q[i];
S*=10;
}
if(flag==0||flag>=res){
a[0]+=res-1;
for(int i=0;i<len;++i)if(a[i]>=10)a[i]-=10,a[i+1]++;
while(a[len])++len;
for(int i=len-1;i>=0;--i)cout<<a[i];cout<<'\n';
return;
}
else{
for(int i=0;i<len;++i)c[i]=a[i];
a[cnt]++;
for(int i=0;i<len;++i)if(a[i]>=10)a[i]-=10,a[i+1]++;
if(a[len])++len;
//for(int i=0;i<cnt;++i)a[i]=0;
int Flag=0;
for(int i=cnt;i<=len;++i){
int F=1;
for(int j=i-cnt;j<i;++j)if(a[j]!=b[j-(i-cnt)])F=0;
if(F)Flag=1;
}
if(Flag){
for(int i=len-1;i>=0;--i)cout<<a[i];cout<<'\n';
return;
}
else{
c[0]+=res-1;
for(int i=0;i<len;++i)if(c[i]>=10)c[i]-=10,c[i+1]++;
while(c[len])++len;
for(int i=len-1;i>=0;--i)cout<<c[i];cout<<'\n';
return;
}
}
}
signed main(){
ios::sync_with_stdio(0);
Q[0]=1;
for(int i=1;i<30;++i)Q[i]=Q[i-1]*10;
int t; cin>>t;
for(int i = 1; i <= t; ++i)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5776kb
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: 103ms
memory: 7696kb
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 76148142411 2814581097 10751244114 78222662280 1767317769 7189709850 90613375429 6552679238 99460821510 5497675063 7787300365 4310767268 48113419640 3265496131 8294404062 28455217540 1114254674 6442013673 3744046867 3289624375 6477935360 12925875411 5504674689 28988291530 7882736025 28460...
result:
wrong answer 2nd lines differ - expected: '7614814251', found: '76148142411'