QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642697 | #8932. Bingo | Wolam# | WA | 45ms | 5700kb | C++17 | 2.4kb | 2024-10-15 15:48:31 | 2024-10-15 15:48:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
string s;
int a[1000025],ans;
int b[1000025],lb;
int M,len,n,sum,lim,m;
bool check()
{
int now=0;
for(int i=len;i>=1;i--)
{
now=now*10+b[i];
}
if(now==m)return 1;
//cerr<<now<<endl;
for(int i=len+1;i<=lb;i++)
{
now=(now-b[i-len])/10;
now+=b[i]*(M/10);
if(now==m)return 1;
}
return 0;
}
void maintain(int x)
{
for(int i=1;i<=lb;i++)
b[i]=0;
for(int i=len+1;i<=n;i++)
b[i]=a[i];
b[1]=x;
lb=n;
for(int i=1;i<=lb;i++)
{
b[i+1]+=b[i]/10;
b[i]%=10;
}
while(b[lb+1])
{
lb++;
b[lb+1]+=b[lb]/10;
b[lb]%=10;
}
}
void solve(void)
{
cin>>s>>m;
M=1;len=0;lim=0;
while(M<=m)M*=10,len++;
n=s.size(),sum=0;
for(int i=n-1;i>=0;i--)
{
sum=(sum*10+s[i]-'0')%m;
a[n-i]=s[i]-'0';
}
ans=m-sum-1;
for(int i=1;i<=18;i++)
a[n+i]=0;
a[1]++;
for(int i=1;i<=n;i++)
{
a[i+1]+=a[i]/10;
a[i]%=10;
}
if(a[n+1])n++;
for(int i=1;i<=n;i++)
b[i]=a[i];
lb=n;
if(check())
ans=0;
lim=0;
for(int i=len;i>=1;i--)
lim=lim*10+a[i];
int t=m;
for(int i=1;i<=len;i++)
{
b[i]=0;
}
for(int i=0;i<=len;i++)
{
if(t<lim)
{
int d=M+t-lim;
if(d>=ans)continue;
maintain(t);
if(check())ans=d;
}
else
{
int d=t-lim;
//cerr<<d<<endl;
if(d>=ans)continue;
maintain(t);
//for(int i=1;i<=lb;i++)
// cout<<b[i]<<" ";
//cout<<endl;
if(check())ans=d;
}
t=t*10%M;
}
a[1]+=ans;
for(int i=1;i<=n;i++)
{
a[i+1]+=a[i]/10;
a[i]%=10;
}
while(a[n+1])
{
n++;
a[n+1]+=a[n]/10;
a[n]%=10;
}
for(int i=n;i>=1;i--)
cout<<a[i];
cout<<'\n';
for(int i=1;i<=lb;i++)
b[i]=0;
for(int i=1;i<=n;i++)
a[i]=0;
lb=0;
}
signed main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5700kb
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: 45ms
memory: 5700kb
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 7614814245 2814581097 1075124402 7822266227 1767317769 7189709874 9061337541 6552679238 9946082151 5497675063 7787300365 4310767268 4811341969 3265496131 8294404058 2845521790 1114254687 6442013673 3744046867 3289624375 6477935373 1292587551 5504674689 2898829180 7882736025 2846033382 923...
result:
wrong answer 2nd lines differ - expected: '7614814251', found: '7614814245'