QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111926#1880. Nikanor Loves GameszhanghaojieWA 2ms3744kbC++141.5kb2023-06-09 10:20:092023-06-09 10:20:12

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-09 10:20:12]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3744kb
  • [2023-06-09 10:20:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N = 1e6+10;
typedef long long LL;
const LL INF = 1e18;

struct Node
{
	int x,opt,v;
}node[N];
LL dp[N],sa[N],sb[N],x[N],y[N],ans;
int n,cnt,q[N],hh,tt;

bool cmp(Node a,Node b)
{
	return a.x<b.x;
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int a,b,c; 
		scanf("%d%d%d",&a,&b,&c);
		if(a>b) swap(a,b);
		node[++cnt]={a,-1,-2*c};
		node[++cnt]={b,1,2*c};
	}
	sort(node+1,node+cnt+1,cmp);
	for(int i=1;i<=cnt;i++)
	{
		sa[i]=sa[i-1];
		if(node[i].opt==1)
		sa[i]+=node[i].v;
	}
	for(int i=cnt;i>=1;i--)
	{
		sb[i]=sb[i+1];
		if(node[i].opt==-1)
		sb[i]+=node[i].v;
	}
	
//	for(int i=1;i<=cnt;i++)
//	cout<<sa[i]<<' ';
//	cout<<endl;
	
	y[0]=sb[1];
	x[0]=1;
	
	for(int i=1;i<=cnt;i++)
	x[i]=node[i].x,y[i]=sa[i]+sb[i+1];
	
//	for(int i=1;i<=cnt;i++)
//	cout<<node[i].x<<' '<<node[i].opt<<' '<<node[i].v<<endl;
//	cout<<endl<<endl<<endl;
	
//	for(int i=0;i<=cnt;i++)
//	cout<<x[i]<<' '<<y[i]<<endl;
	
	ans=sb[1]-1;
	for(int i=1;i<=cnt;i++)
	{
		while(hh<tt&&(double)(y[i]-y[q[tt]])/(x[i]-x[q[tt]])>=(double)(y[i]-y[q[tt-1]])/(x[i]-x[q[tt-1]]))
		tt--;
		q[++tt]=i;
		
		LL k=4*node[i].x;
		int l=hh,r=tt;
		while(l<r)
		{
			int mid=l+r>>1;
			if((double)(y[q[mid+1]]-y[q[mid]])/(x[q[mid+1]]-x[q[mid]])>k) l=mid+1;
			else r=mid;
		}
		dp[i]=-k*x[q[l]]+y[q[l]]+sa[i]+sb[i+1];
//		cout<<dp[i]<<' ';
		ans=max(ans,dp[i]);
	}
//	cout<<endl;
	printf("%.8lf",(double)ans/4);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3740kb

input:

2
1 4 15
3 5 10

output:

2.50000000

result:

ok found '2.5000000', expected '2.5000000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3744kb

input:

1
2 2 8

output:

4.00000000

result:

ok found '4.0000000', expected '4.0000000', error '0.0000000'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3740kb

input:

3
94 68 49
51 2 63
26 85 20

output:

-66.25000000

result:

wrong answer 1st numbers differ - expected: '-73.0000000', found: '-66.2500000', error = '0.0924658'