QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#539917 | #8932. Bingo | ucup-team4717# | TL | 8ms | 58888kb | C++17 | 2.9kb | 2024-08-31 16:01:56 | 2024-08-31 16:01:57 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
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],tmp[N];
void check(){
for(int i=n;i>=1;i--){
if(tmp[i]>a[i])return;
if(tmp[i]<a[i]){
for(int j=1;j<=n;j++)a[j]=tmp[j];
return;
}
}
}
void sol(){
// fill(a+1,a+n+20,0),fill(b+1,b+m+20,0),fill(c+1,c+n+20,0);
memset(a,0,sizeof a),memset(b,0,sizeof b),memset(c,0,sizeof c);
n=0,m=0,mod=0;
char ch=getch();
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];
if(n<m){
for(int i=m;i>=1;i--)write(b[i]);putch('\n');
return;
}
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+1])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';
int asdasd=0;
for(int i=m;i<=n;i++){
int flag=1;
for(int j=m;j>=1;j--)
if(c[i-(m-j)]!=b[j])flag=0;
if(flag)asdasd=1;
}
if(asdasd){
if(!c[n])n--;
for(int i=n;i>=1;i--)write(c[i]);putch('\n');
return;
}
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;}
}
if(flag){
for(int j=n;j>i;j--)tmp[n]=c[j];
for(int j=m;j>=1;j--)tmp[i-(m-j)]=b[j];
for(int j=i-m;j>=1;j--)tmp[j]=0;
check();
}
}
while(!a[n])n--;
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: 100
Accepted
time: 8ms
memory: 58888kb
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
Time Limit Exceeded
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 ...