QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#539333 | #8932. Bingo | ucup-team4717# | WA | 2ms | 13908kb | C++17 | 2.6kb | 2024-08-31 14:32:45 | 2024-08-31 14:32:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace IO{
char buff[1<<21],*p1=buff,*p2=buff;
char getch(){
return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
}
template<typename T>
void read(T &x){
char ch=getch();int fl=1;x=0;
while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
x*=fl;
}
template<typename T,typename ...Args>
void read(T &x,Args& ...args){
read(x);read(args...);
}
char obuf[1<<21],*p3=obuf;
void putch(char ch){
if(p3-obuf<(1<<21))*p3++=ch;
else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
}
char ch[100];
template<typename T>
void write(T x){
if(!x)return putch('0');
if(x<0)putch('-'),x*=-1;
int top=0;
while(x)ch[++top]=x%10+48,x/=10;
while(top)putch(ch[top]),top--;
}
template<typename T,typename ...Args>
void write(T x,Args ...args){
write(x);write(args...);
}
void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=2e6+6;
int n,m,mod;
char sa[N],sb[N];
int a[N],b[N],c[N];
void sol(){
fill(a+1,a+n+1,0),fill(b+1,b+m+1,0),fill(c+1,c+n+1,0);
n=0,m=0,mod=0;
char ch=getchar();
while(!isdigit(ch))ch=getch();
while(isdigit(ch))sa[++n]=ch,ch=getch();
while(!isdigit(ch))ch=getch();
while(isdigit(ch))sb[++m]=ch,ch=getch();
for(int i=1;i<=n;i++)c[n-i+1]=a[n-i+1]=sa[i]-'0';
for(int i=1;i<=m;i++)b[m-i+1]=sb[i]-'0';
for(int i=m;i>=1;i--)mod=10*mod+b[i];
int cnt=0;for(int i=n;i>=1;i--)cnt=(10ll*cnt+a[i])%mod;cnt=mod-cnt;
a[1]+=cnt;for(int i=1;i<=n;i++)a[i+1]+=a[i]/10,a[i]%=10;if(a[n]>=10)a[n+1]+=a[n]/10,a[n]%=10,n++;
c[1]+=1;for(int i=1;i<=n;i++)c[i+1]+=c[i]/10,c[i]%=10;
// for(int i=n;i>=1;i--)cout<<a[i];cout<<'\n';
// for(int i=n;i>=1;i--)cout<<c[i];cout<<'\n';
// for(int i=m;i>=1;i--)cout<<b[i];cout<<'\n';
for(int i=n;i>=m;i--){
int flag=1;
for(int j=m;j>=1;j--){
if(c[i-(m-j)]<b[j])break;
if(c[i-(m-j)]>b[j]){flag=0;break;}
}
for(int j=m;j>=1;j--){
if(a[i-(m-j)]>b[j])break;
if(a[i-(m-j)]<b[j]){flag=0;break;}
}
if(flag){
for(int j=n;j>i;j--)write(a[j]);
int ops=1;
for(int j=m;j>=1;j--){
if(b[j]>c[i-(m-j)])ops=0;
write(b[j]);
}
for(int j=i-m;j>=1;j--){
if(ops==0)write(0);
else write(c[j]);
}
putch('\n');
return;
}
}
for(int i=n;i>=1;i--)write(a[i]);putch('\n');
return;
}
signed main(){
int T;
read(T);
while(T--)sol();
flush();
return 0;
}/*
1
1369 37
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 13908kb
input:
6 7 3 12 3 9 10 249 51 1369 37 2 1
output:
9 13 0 251 1370 3
result:
wrong answer 3rd lines differ - expected: '10', found: '0'