QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#115452#5957. Allergy Testing zhouhuanyi0 614ms402252kbC++111.8kb2023-06-26 09:41:102023-06-26 09:41:13

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-26 09:41:13]
  • 评测
  • 测评结果:0
  • 用时:614ms
  • 内存:402252kb
  • [2023-06-26 09:41:10]
  • 提交

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
    {
	cout<<x-y<<':'<<y<<'!'<<endl;
	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: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

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:

477:3!
476:3!
475:3!
474:3!
473:3!
472:3!
471:3!
470:3!
469:3!
468:3!
467:3!
466:3!
465:4!
464:4!
463:4!
462:4!
461:4!
460:4!
459:4!
458:4!
457:4!
456:4!
455:4!
454:5!
453:5!
452:5!
451:5!
450:5!
449:5!
448:5!
447:5!
446:5!
445:5!
444:5!
443:5!
442:6!
441:6!
440:6!
439:6!
438:6!
437:6!
436:6!
435:6!...

result:


Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 614ms
memory: 402252kb

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:

114:3!
113:3!
112:3!
111:4!
110:4!
109:4!
108:5!
107:5!
106:5!
105:6!
104:6!
103:6!
102:7!
101:7!
100:7!
99:8!
98:8!
97:8!
96:9!
95:9!
94:9!
93:10!
92:10!
91:10!
90:11!
89:11!
88:11!
87:12!
84:13!
54:23!
51:24!
48:25!
45:26!
42:27!
39:28!
36:29!
33:30!
30:31!
27:32!
24:33!
21:34!
18:35!
17:35!
16:35...

result:

wrong answer 1st lines differ - expected: 'Case #1: 12699968455924', found: '114:3!'