QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#115454 | #5957. Allergy Testing | zhouhuanyi | 50 ✓ | 203ms | 402012kb | C++11 | 1.8kb | 2023-06-26 09:41:40 | 2023-06-26 09:41:51 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define N 1000000
#define M 50
#define inf 1e18
using namespace std;
long long read()
{
char c=0;
long long sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int T,length;
long long n,A,B,dp[N+1][M+1];
long long C(long long x,int y)
{
if (x<y) return 0;
if (!y) return 1;
else if (y==1) return min(x,n+1);
else if (y==2) return min((long long)(((__int128)(x)*(x-1))>>1),n+1);
else return min(dp[x-y][y],n+1);
}
long long calc(long long l,long long r,int d)
{
if (!d) return min(r-l+1,n+1);
else if (d==1) return min(((__int128)(r+1)*(r+2)>>1)-((__int128)(l)*(l+1)>>1),(__int128)(n+1));
else
{
double res=1;
long long rst=0;
for (int i=1;i<=d;++i)
{
res=res*(r-i+1)/i;
if (res>(n+1)*2) return n+1;
}
for (int i=r;i>=l;--i)
{
rst=min(rst+C(i+d,d),n+1);
if (rst==n+1) return n+1;
}
return rst;
}
}
long long F(long long x)
{
if (x/B>=50) return n+1;
long long d,c,l,sl,sr,res=0,rst;
for (int i=0;i<=49;++i)
if (i*B<=x)
{
d=x-i*B,l=max(d-(B-1),0ll),sl=(l+A-1)/A,sr=d/A;
if (sl<=sr) res=min(res+calc(sl,sr,i),n+1);
}
return res;
}
int main()
{
long long res;
dp[0][0]=1;
for (int i=0;i<=N;++i)
for (int j=0;j<=M;++j)
{
if (i) dp[i][j]=min(dp[i][j]+dp[i-1][j],(long long)(inf));
if (j) dp[i][j]=min(dp[i][j]+dp[i][j-1],(long long)(inf));
}
T=read();
for (int qt=1;qt<=T;++qt)
{
n=read(),A=read(),B=read(),res=-1;
for (int i=log(inf)/log(2);i>=0;--i)
if (res+(1ll<<i)<=inf&&F(res+(1ll<<i))<n)
res+=(1ll<<i);
res++;
printf("Case #%d: %lld\n",qt,res);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 15
Accepted
Test #1:
score: 15
Accepted
time: 84ms
memory: 402012kb
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: 203ms
memory: 401900kb
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