QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#698811#5978. Runaway QuailFLY23 ✓2401ms7236kbC++142.0kb2024-11-01 22:09:132024-11-01 22:09:13

Judging History

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

  • [2024-11-01 22:09:13]
  • 评测
  • 测评结果:23
  • 用时:2401ms
  • 内存:7236kb
  • [2024-11-01 22:09:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define gc getchar
#define pb push_back
#define all(x) x.begin(),x.end()
#define y1 __
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define dFor(i,a,b) for(int i=(a);i>=(b);i--)
#define tomin(x,y) x=min(x,y)
#define tomax(x,y) x=max(x,y)
#define abs_(x) max(x,-(x))
#define eq(x,y) (abs_((x)-(y))<=eps)
#define ull unsigned long long
const int N=505;
const db eps=1e-12,I=1e18;
int read()
{
	int x=0; int y=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') y=0;
	for(;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^48);
	return y?x:-x;
}
char getc() { char c=getchar(); for(;!isdigit(c)&&!isalpha(c);c=getchar()); return c; }
int n;
db Y;
struct _N
{
	int x,y;
	bool operator <(_N t)const
	{
		if(y^t.y) return y<t.y;
		if(x>0) return x<t.x;
		return x>t.x;
	}
}a[N],b[N];
int c1[N],c2[N];
int ct1,ct2;
db f[N][N];
db cost(_N x,db y) { return (x.x+y*x.y)*1.0/(Y-x.y); }
db pos(_N x,db nw) { return x.x+x.y*nw; }
db work()
{
	Y=read(); n=read();
	For(i,1,n) c1[i]=read();
	For(i,1,n) c2[i]=read();
	ct1=ct2=0;
	For(i,1,n) 
	{
		if(c1[i]>0) a[++ct1]=(_N){c1[i],c2[i]};
		else b[++ct2]=(_N){-c1[i],c2[i]};
	}
	sort(a+1,a+ct1+1);
	sort(b+1,b+ct2+1);
	For(i,0,ct1) For(j,0,ct2) f[i][j]=I;
	f[ct1][ct2]=0;
	dFor(i,ct1,0) dFor(j,ct2,0)
	{
		db nw=f[i][j],st1=pos(a[i],nw),st2=pos(b[j],nw),s=0;
		dFor(k,i,1)
		{
			if(pos(a[k],nw)>=st1-eps) tomax(s,cost(a[k],nw));
			tomin(f[k-1][j],nw+s*2-(k==1&&j==0?s:0));
		}
		s=0; 
		dFor(k,j,1)
		{
//			cout<<i<<" "<<j<<" "<<k<<" "<<nw<<"   "<<pos(b[k],nw)<<" "<<st2<<"  "<<cost(b[k])<<endl;
			if(pos(b[k],nw)>=st2-eps) tomax(s,cost(b[k],nw));
//			cout<<s<<endl;
			tomin(f[i][k-1],nw+s*2-(k==1&&i==0?s:0));
		}
	} 
	return f[0][0];
}
int main()
{
//	freopen("tiii.in","r",stdin);
//	freopen("tiii.out","w",stdout); 
	int T=read();
	For(i,1,T) printf("Case #%d: %.9Lf\n",i,work());
//	while(T--) printf("%d\n",work());
	return 0;
}
/*



*/


Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 1ms
memory: 5968kb

input:

50
4 3
-3 -6 -9
3 2 1
2 2
1 -1
1 1
1000 25
769234 -5735820 -524288 -5403090 -6429140 1574982 1 -9733628 -1407481 4093041 4117720 -3193501 -9765195 -3069520 1122216 -5799108 131072 -8482066 -256 -8021159 -8958386 -7027036 5370579 -3602534 -6834567
425 102 744 155 339 19 999 19 159 198 51 304 369 601 ...

output:

Case #1: 3.000000000
Case #2: 5.000000000
Case #3: 51133.937500000
Case #4: 429262.396142110
Case #5: 129368.012279597
Case #6: 7801.832031250
Case #7: 66656.812500000
Case #8: 607220.690423515
Case #9: 5725896.876344086
Case #10: 129205.285220126
Case #11: 64298.000000000
Case #12: 610881.705159705...

result:

ok correct! (50 test cases)

Subtask #2:

score: 15
Accepted

Test #2:

score: 15
Accepted
time: 2401ms
memory: 7236kb

input:

50
4 3
-3 -6 -9
3 2 1
2 2
1 -1
1 1
1000 500
-9650379 9806301 -6495789 -1283284 5022779 4725553 9364178 -8123302 -9609729 7847458 -142364 6983908 8147008 -3186924 7339254 -8737645 8757174 7887319 3609962 5780915 -1752801 -1657946 -9511339 5113995 -7887160 -6093170 260267 -3837106 -356098 6676924 6210...

output:

Case #1: 3.000000000
Case #2: 5.000000000
Case #3: 205911250.088888889
Case #4: 36298.000000000
Case #5: 186002.250000000
Case #6: 13741948.500000000
Case #7: 109001.125000000
Case #8: 38656.812500000
Case #9: 128881.056148055
Case #10: 8069407.987096774
Case #11: 128881.056148055
Case #12: 124955.3...

result:

ok correct! (50 test cases)

Extra Test:

score: 0
Extra Test Passed