QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#423725 | #5957. Allergy Testing | zjy0001 | 50 ✓ | 82ms | 20276kb | C++17 | 1.3kb | 2024-05-28 15:41:53 | 2024-05-28 15:41:53 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long
using namespace std;
const LL INF=1e17;
LLL preC[60][1000005];int pos[60];
inline LL C2(const LL&n){return n*(n-1)/2;}
inline LL calc(LL l,LL r,int m){
if(l>r)return 0;
if(m==0)return r-l+1;
if(m==1)return min((LLL)(l+r+2)*(r-l+1)/2,(LLL)INF);
if(m==2){
if(r>1e9)return INF;
LL z=0;
for(LL i=r;i>=l&&z<INF;--i)z+=C2(i+2);
return z;
}
return r+m<pos[m]?min(preC[m][r+m]-preC[m][l+m-1],(LLL)INF):INF;
}
inline LL solve(LL k,LL a,LL b){
LL ans=0;
for(int x=0;x*b<=k&&ans<INF;++x)ans+=calc(max(0ll,k-x*b+a-b)/a,(k-x*b)/a,x);
return ans;
}
inline void MAIN(){
LL n,a,b,ans=-1;cin>>n>>a>>b;
for(LL l=0,r=b*ceil(log2l(n));l<=r;){
const LL mid=(l+r)>>1;
if(solve(mid,a,b)>=n)ans=mid,r=mid-1;
else l=mid+1;
}
cout<<ans<<'\n';
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
for(int m=3;m<60;++m)for(pos[m]=m;(preC[m][pos[m]]=(m>3?preC[m-1][pos[m]-1]:C2(pos[m]-1))+preC[m][pos[m]-1])<INF;++pos[m]);
for(int m=3;m<60;++m)for(int i=m+1;i<pos[m];++i)preC[m][i]+=preC[m][i-1];
int t=1;cin>>t;for(int _=1;t--;++_)cout<<"Case #"<<_<<": ",MAIN();
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 15
Accepted
Test #1:
score: 15
Accepted
time: 3ms
memory: 20232kb
input:
200 248794459979751 2 23 647141011809434 1 1 1 7 72 440039160553207 2 15 518185192633838 50 99 723438516824256 1 19 367397848971042 72 74 161202117156326 40 40 14195704645139 1 1 344123426089538 17 70 597633495749779 3 74 1 31 89 899376930571631 3 52 776312678496459 1 1 657958323101218 1 91 73670160...
output:
Case #1: 395 Case #2: 50 Case #3: 0 Case #4: 305 Case #5: 3527 Case #6: 286 Case #7: 3572 Case #8: 1920 Case #9: 44 Case #10: 1783 Case #11: 1022 Case #12: 0 Case #13: 812 Case #14: 50 Case #15: 883 Case #16: 2957 Case #17: 245 Case #18: 870 Case #19: 917 Case #20: 88 Case #21: 49 Case #22: 4188 Cas...
result:
ok 200 lines
Subtask #2:
score: 35
Accepted
Test #2:
score: 35
Accepted
time: 82ms
memory: 20276kb
input:
200 746993929581932 142696274786 428088824356 821296104130392 9404 314602795522 732393029543810 1 491862101132 334980960239832 476164015712 689458402567 34360471927936 219762102255 749514425501 43149753727929 2637 277305648790 1 306403840371 881644374633 6764562905980 1 1 515691552138897 74612952475...
output:
Case #1: 12699968455924 Case #2: 630293201260 Case #3: 491900360801 Case #4: 27974938038696 Case #5: 19244380182431 Case #6: 301802693346 Case #7: 0 Case #8: 43 Case #9: 41692108300684 Case #10: 12759827966790 Case #11: 44 Case #12: 681182597827 Case #13: 12933280433300 Case #14: 8375286538639 Case ...
result:
ok 200 lines
Extra Test:
score: 0
Extra Test Passed