QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#829450 | #8932. Bingo | 2021cyq# | TL | 12ms | 41068kb | C++14 | 4.7kb | 2024-12-24 10:04:24 | 2024-12-24 10:04:24 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define bll __int128
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define sec second
#define vii vector<int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define pii pair<int,int>
#define pil pair<int,ll>
#define re register
#define puu pair<ull,ull>
#define clr clear
#define vpi vector<pii>
#define qii queue<int>
using namespace std;
namespace io{
const int __SIZE=(1<<22)+1;
char ibuf[__SIZE],*iS,*iT,obuf[__SIZE],*oS=obuf,*oT=oS+__SIZE-1,__c,qu[55];int __f,qr,_eof;
#define Gc()(iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,__SIZE,stdin),(iS==iT?EOF:*iS++)):*iS++)
inline void flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf;}
inline void gc(char&x){x=Gc();}
inline void pc(char x){*oS++=x;if(oS==oT)flush();}
inline void pstr(const char*s){int __len=strlen(s);for(__f=0;__f<__len;++__f)pc(s[__f]);}
inline void gstr(char*s){for(__c=Gc();__c<32||__c>126||__c==' ';)__c=Gc();
for(;__c>31&&__c<127&&__c!=' ';++s,__c=Gc())*s=__c;*s=0;}
template<class I>inline bool read(I&x){_eof=0;
for(__f=1,__c=Gc();(__c<'0'||__c>'9')&&!_eof;__c=Gc()){if(__c=='-')__f=-1;_eof|=__c==EOF;}
for(x=0;__c<='9'&&__c>='0'&&!_eof;__c=Gc())x=x*10+(__c&15),_eof|=__c==EOF;x*=__f;return!_eof;}
template<class I>inline void write(I x){if(!x)pc('0');if(x<0)pc('-'),x=-x;
while(x)qu[++qr]=x%10+'0',x/=10;while(qr)pc(qu[qr--]);}
struct Flusher_{~Flusher_(){flush();}}io_flusher_;
}using io::pc;using io::gc;using io::pstr;using io::gstr;using io::read;using io::write;
const int N=1e6+5;
int n,m,T;
ll x;
string str;
struct Big{
int a[N],len;
void pre(){memset(a,0,sizeof(a)),len=0;}
void chk()
{
for(int i=1;i<=len;i++)
{
if(a[i]>=10)
{
a[i+1]+=a[i]/10,a[i]%=10;
if(i==len)len++;
}
if(a[i]<0)a[i+1]--,a[i]+=10;
}
while(a[len]==0)len--;
}
void get(ll x){memset(a,0,sizeof(a)),len=0;while(x)a[++len]=x%10,x/=10;}
void print(){for(int i=len;i>=1;i--)cout<<a[i];cout<<'\n';}
}a,b[35];
Big z,oo;
const Big & operator +(const Big&x,const Big&y)
{
z.pre(),z.len=max(x.len,y.len);
for(int i=1;i<=max(x.len,y.len);i++)z.a[i]=x.a[i]+y.a[i];
z.chk();return z;
}
const Big & operator +(const Big&x,int y)
{
static Big Y;Y.get(y);
return (x+Y);
}
const Big & operator -(const Big&x,const Big&y)
{
z.pre(),z.len=max(x.len,y.len);
for(int i=1;i<=max(x.len,y.len);i++)z.a[i]=x.a[i]-y.a[i];
z.chk();return z;
}
const Big & operator -(const Big&x,int y)
{
static Big Y;Y.get(y);
return x-Y;
}
const Big & operator *(const Big&x,const Big&y)
{
z.pre(),z.len=x.len+y.len-1;
for(int i=1;i<=x.len;i++)for(int j=1;j<=y.len;j++)z.a[i+j-1]+=x.a[i]*y.a[j];
z.chk();return z;
}
const Big & operator *(const Big&x,int y)
{
z.pre(),z.len=x.len;
for(int i=1;i<=x.len;i++)z.a[i]=x.a[i]*y;
z.chk();return z;
}
const Big & operator /(const Big&x,int y)
{
z.pre(),z.len=x.len;
int res=0;
for(int i=x.len;i>=1;i--)res=res*10+x.a[i],z.a[i]=res/y,res%=y;
z.chk();return z;
}
bool operator<(const Big&x,const Big&y)
{
if(x.len!=y.len)return x.len<y.len;
for(int i=x.len;i>=1;i--)if(x.a[i]!=y.a[i])return x.a[i]<y.a[i];
return false;
}
bool operator<=(const Big&x,const Big&y)
{
if(x.len!=y.len)return x.len<y.len;
for(int i=x.len;i>=1;i--)if(x.a[i]!=y.a[i])return x.a[i]<y.a[i];
return true;
}
bool operator>(const Big&x,const Big&y)
{
if(x.len!=y.len)return x.len>y.len;
for(int i=x.len;i>=1;i--)if(x.a[i]!=y.a[i])return x.a[i]>y.a[i];
return false;
}
bool operator>=(const Big&x,const Big&y)
{
if(x.len!=y.len)return x.len>y.len;
for(int i=x.len;i>=1;i--)if(x.a[i]!=y.a[i])return x.a[i]>y.a[i];
return true;
}
int count(int x)
{
int s=0;
while(x)x/=10,s++;
return s;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>T;
while(T--)
{
cin>>str>>m,n=str.length(),x=0,a.len=n;
int len=0,c=count(m);
Big now;now.get(m);
for(int i=1;i<=n;i++)a.a[i]=str[n-(i-1)-1]-'0';
a=a+1;
if(a<now){now.print();continue;}
for(int i=n;i>=1;i--)x=x*10+a.a[i],x%=m;
b[++len]=a+(int)(m-x)%m;
int bbzz=0;
for(int i=c;i<=n;i++)
{
int bz=0;
for(int j=i;j>=i-c+1;j--)if(now.a[j-(i-c+1)+1]!=a.a[j]){bz=1;break;}
if(bz)continue;
bbzz=1;
}
if(bbzz){a.print();continue;}
for(int i=c;i<=n&&len<=2*c+2;i++)
{
int bz=0;
for(int j=i;j>=i-c+1;j--)
{
if(now.a[j-(i-c+1)+1]<a.a[j]){bz=1;break;}
else if(now.a[j-(i-c+1)+1]>a.a[j])break;
}
if(!bz)
{
b[++len]=a;
for(int j=i;j>=i-c+1;j--)b[len].a[j]=now.a[j-(i-c+1)+1];
for(int j=i-c;j>=1;j--)b[len].a[j]=0;
}
}
Big A;A.len=1e9;
for(int i=1;i<=len;i++)if(A>b[i])A=b[i];
A.print();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 41068kb
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 ...