QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720400 | #8347. 毒假强 | ffffyc | 100 ✓ | 34ms | 6116kb | C++14 | 3.3kb | 2024-11-07 12:27:01 | 2024-11-07 12:27:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lll __int128
namespace IO{//by cyffff
int len=0;
char ibuf[(1<<21)+1],*iS,*iT,out[(1<<25)+1];
#if ONLINE_JUDGE
#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
#else
#define gh() getchar()
#endif
#define reg register
inline ll read(){
reg char ch=gh();
reg ll x=0;
reg char t=0;
while(ch<'0'||ch>'9') t|=ch=='-',ch=gh();
while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
return t?-x:x;
}
inline void putc(char ch){
out[len++]=ch;
}
template<class T>
inline void write(T x){
if(x<0)putc('-'),x=-x;
if(x>9)write(x/10);
out[len++]=x%10+48;
}
inline void flush(){
fwrite(out,1,len,stdout);
len=0;
}
inline char getc(){
char ch=gh();
while(ch<'A'||ch>'Z') ch=gh();
return ch;
}
}
using IO::read;
using IO::write;
using IO::flush;
using IO::getc;
using IO::putc;
#define pii pair<int,int>
#define mpr make_pair
#define fir first
#define sec second
const int N=64+10;
const ll INF=2e18;
template<class T>
inline void writec(T x){
if(x<0)putchar('-'),x=-x;
if(x>9)writec(x/10);
putchar(x%10+48);
}
inline void inc(lll &x,lll y){
x+=y;
if(x>INF) x=INF;
}
int k,w[128];
ll c=1,n;
/*
inline lll check(lll x){
lll dn=x%B,up=x/B;
lll dw=dn*c+1;
lll ddw=dw%B,udw=dw/B;
lll uw=up*c+udw;
int d=0;
if(uw){
for(int i=0;i<=17;i++) w[d++]=ddw%10,ddw/=10;
while(uw) w[d++]=uw%10,uw/=10;
}else{
while(ddw) w[d++]=ddw%10,ddw/=10;
}
}
lll L=1,R=1e36,ans=R;
while(L<=R){
lll mid=(L+R)/2;
if(check(mid)>=n) R=mid-1,ans=mid;
else L=mid+1;
}
*/
int ck[N],rd[N];
lll f[N][N][N*10];
//f_{i,j,v} 第 i 列第 j 行,进位为 v
inline lll calc(lll v,int dt){
// puts("-----");
// writec(v),printf(" %d!\n",dt);
memset(rd,0,sizeof(rd));
for(int i=0;i<dt;i++)
rd[i]=-1;
int d=dt;
while(v){
if(v%10==9) return 0;
rd[d++]=v%10,v/=10;
}
// for(int i=0;i<d;i++) printf("%d ",rd[i]);puts("");
lll sum=0;
int rc=(d+k-1)/k;
// printf("rc=%d\n",rc);
for(int t=0;t<=rc+2;t++){
lll tv=t*c;
// printf("tv=%lld\n",(ll)tv);
f[0][0][0]=1;
for(int i=0;i<k;i++,tv/=10)
for(int j=0;j<=rc;j++){
for(int v=0;v<=rc*10;v++){
lll w=f[i][j][v];
if(!w) continue;
f[i][j][v]=0;
if(j<rc){
int tp=rd[j*k+i];
// printf("(%d,%d) %d %d\n",i,j,v,tp);
if(tp==-1){
for(int k=0;k<9;k++)
inc(f[i][j+1][v+k],w);
}else{
if(tp==9) continue;
inc(f[i][j+1][v+tp],w);
}
}else{
if(v%10!=tv%10) continue;
inc(f[i+1][0][v/10],w);
}
}
}
if(tv<=rc*10) /*printf("%d %lld\n",t,(ll)f[k][0][tv]),*/inc(sum,f[k][0][tv]);
for(int v=0;v<=rc*10;v++)
f[k][0][v]=0;
}
// writec(sum),puts("");
return sum;
}
int main(){
// freopen("data3.in","r",stdin);
// freopen("tes.out","w",stdout);
k=read(),n=read()+1;
for(int i=1;i<=k;i++) c*=10;
c--;
int d=0;
lll tp=1;
while(calc(0,d+1)<n) d++,tp*=10;
// printf("%d %d\n",(int)c,d);
lll ans=0,s=0;
for(int i=d;i>=0;i--,tp/=10){
for(int v=0;v<=9;v++){
lll ct=calc(s*10+v,i);
// printf("%d %d %d\n",v,d,(int)ct);
if(n>ct) n-=ct;
else{
ans+=v*tp,s=s*10+v;
break;
}
}
}
// writec(ans),puts("");
write(ans/c);
flush();
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 25
Accepted
Test #1:
score: 25
Accepted
time: 1ms
memory: 5624kb
input:
2 653
output:
1069
result:
ok single line: '1069'
Test #2:
score: 25
Accepted
time: 1ms
memory: 5692kb
input:
2 729
output:
1168
result:
ok single line: '1168'
Test #3:
score: 25
Accepted
time: 1ms
memory: 5684kb
input:
2 378
output:
569
result:
ok single line: '569'
Test #4:
score: 25
Accepted
time: 0ms
memory: 5676kb
input:
3 673
output:
1329
result:
ok single line: '1329'
Test #5:
score: 25
Accepted
time: 1ms
memory: 5588kb
input:
3 803
output:
1514
result:
ok single line: '1514'
Test #6:
score: 25
Accepted
time: 1ms
memory: 5708kb
input:
3 999
output:
1772
result:
ok single line: '1772'
Test #7:
score: 25
Accepted
time: 1ms
memory: 5844kb
input:
1 754
output:
1142
result:
ok single line: '1142'
Test #8:
score: 25
Accepted
time: 1ms
memory: 5736kb
input:
3 673
output:
1329
result:
ok single line: '1329'
Test #9:
score: 25
Accepted
time: 1ms
memory: 5708kb
input:
3 728
output:
1390
result:
ok single line: '1390'
Test #10:
score: 25
Accepted
time: 0ms
memory: 5704kb
input:
3 644
output:
1277
result:
ok single line: '1277'
Test #11:
score: 25
Accepted
time: 1ms
memory: 5920kb
input:
3 403
output:
734
result:
ok single line: '734'
Test #12:
score: 25
Accepted
time: 1ms
memory: 5684kb
input:
2 196
output:
286
result:
ok single line: '286'
Test #13:
score: 25
Accepted
time: 1ms
memory: 5616kb
input:
1 73
output:
90
result:
ok single line: '90'
Test #14:
score: 25
Accepted
time: 0ms
memory: 5684kb
input:
2 661
output:
1079
result:
ok single line: '1079'
Test #15:
score: 25
Accepted
time: 0ms
memory: 5620kb
input:
1 648
output:
889
result:
ok single line: '889'
Subtask #2:
score: 35
Accepted
Test #16:
score: 35
Accepted
time: 22ms
memory: 5648kb
input:
1 345034715579071096
output:
2513029422339367072
result:
ok single line: '2513029422339367072'
Test #17:
score: 35
Accepted
time: 26ms
memory: 5708kb
input:
1 928064447724082316
output:
6841649390539291284
result:
ok single line: '6841649390539291284'
Test #18:
score: 35
Accepted
time: 23ms
memory: 5996kb
input:
1 541392330132197148
output:
3934945708734153715
result:
ok single line: '3934945708734153715'
Test #19:
score: 35
Accepted
time: 22ms
memory: 5768kb
input:
1 932096632324717020
output:
6866796948572468426
result:
ok single line: '6866796948572468426'
Test #20:
score: 35
Accepted
time: 30ms
memory: 5764kb
input:
1 114451898294099023
output:
751984975176342275
result:
ok single line: '751984975176342275'
Test #21:
score: 35
Accepted
time: 20ms
memory: 5764kb
input:
1 235498410350575794
output:
1678575115834518445
result:
ok single line: '1678575115834518445'
Test #22:
score: 35
Accepted
time: 23ms
memory: 5804kb
input:
1 263087596959546780
output:
1854129753611416834
result:
ok single line: '1854129753611416834'
Test #23:
score: 35
Accepted
time: 26ms
memory: 6004kb
input:
1 576677905677423798
output:
4168653345619750896
result:
ok single line: '4168653345619750896'
Test #24:
score: 35
Accepted
time: 23ms
memory: 5932kb
input:
1 715338160945566811
output:
5200349120580131175
result:
ok single line: '5200349120580131175'
Test #25:
score: 35
Accepted
time: 22ms
memory: 5932kb
input:
1 732471942288061103
output:
5313900915618634928
result:
ok single line: '5313900915618634928'
Test #26:
score: 35
Accepted
time: 18ms
memory: 5620kb
input:
1 81591921669173834
output:
533613350411224447
result:
ok single line: '533613350411224447'
Test #27:
score: 35
Accepted
time: 24ms
memory: 5804kb
input:
1 444041620832982561
output:
3172902012381803952
result:
ok single line: '3172902012381803952'
Test #28:
score: 35
Accepted
time: 19ms
memory: 5692kb
input:
1 6697181292380282
output:
39407408296042592
result:
ok single line: '39407408296042592'
Test #29:
score: 35
Accepted
time: 21ms
memory: 5696kb
input:
1 952035664236484391
output:
7007633864782456009
result:
ok single line: '7007633864782456009'
Test #30:
score: 35
Accepted
time: 22ms
memory: 5700kb
input:
1 119337166106580019
output:
792828609748126894
result:
ok single line: '792828609748126894'
Subtask #3:
score: 40
Accepted
Test #31:
score: 40
Accepted
time: 3ms
memory: 5800kb
input:
12 874620678069272691
output:
22463825142185819370
result:
ok single line: '22463825142185819370'
Test #32:
score: 40
Accepted
time: 4ms
memory: 5860kb
input:
16 802614516796786027
output:
35407415665622422294
result:
ok single line: '35407415665622422294'
Test #33:
score: 40
Accepted
time: 5ms
memory: 5852kb
input:
6 756647802834648987
output:
10438847716008292465
result:
ok single line: '10438847716008292465'
Test #34:
score: 40
Accepted
time: 3ms
memory: 6004kb
input:
3 226896403387130337
output:
2059211761939710776
result:
ok single line: '2059211761939710776'
Test #35:
score: 40
Accepted
time: 25ms
memory: 5996kb
input:
1 347488145421093192
output:
2527387074818969159
result:
ok single line: '2527387074818969159'
Test #36:
score: 40
Accepted
time: 4ms
memory: 5928kb
input:
14 193000621330864201
output:
6067357863414375200
result:
ok single line: '6067357863414375200'
Test #37:
score: 40
Accepted
time: 5ms
memory: 5740kb
input:
6 954115818600650251
output:
12864634150158375562
result:
ok single line: '12864634150158375562'
Test #38:
score: 40
Accepted
time: 5ms
memory: 6116kb
input:
17 743225133605738266
output:
37311263433846176756
result:
ok single line: '37311263433846176756'
Test #39:
score: 40
Accepted
time: 4ms
memory: 5840kb
input:
9 252020961388627232
output:
4250078145252196572
result:
ok single line: '4250078145252196572'
Test #40:
score: 40
Accepted
time: 4ms
memory: 5896kb
input:
12 625490241962472026
output:
15466218565422592895
result:
ok single line: '15466218565422592895'
Test #41:
score: 40
Accepted
time: 5ms
memory: 5916kb
input:
17 954452527346520859
output:
48142667151713611623
result:
ok single line: '48142667151713611623'
Test #42:
score: 40
Accepted
time: 7ms
memory: 5772kb
input:
3 976431687783080972
output:
8829664277323469345
result:
ok single line: '8829664277323469345'
Test #43:
score: 40
Accepted
time: 34ms
memory: 5968kb
input:
1 847601466910992894
output:
6192959617472541715
result:
ok single line: '6192959617472541715'
Test #44:
score: 40
Accepted
time: 2ms
memory: 5760kb
input:
4 151280662907406040
output:
1473815899034367653
result:
ok single line: '1473815899034367653'
Test #45:
score: 40
Accepted
time: 6ms
memory: 5772kb
input:
2 888548487913703829
output:
7283410115572769456
result:
ok single line: '7283410115572769456'