QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#34016#1880. Nikanor Loves GamesmoyujiangWA 3ms9768kbC++1.4kb2022-06-05 14:55:292022-06-05 14:55:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-05 14:55:29]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9768kb
  • [2022-06-05 14:55:29]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a),i##END=(b);i<=i##END;i++)
#define Rof(i,b,a) for(int i=(b),i##END=(a);i>=i##END;i--)
#define go(u) for(int i=head[u];i;i=nxt[i])
#define int long long
using namespace std;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}
const int N=2e6+10;
#define fi first
#define se second
int n,m,sum,c;
map<int,int> mp;
int val[N],id[N];
struct node{
	int x,y;
	int val(int a){return x*a+y;}
}q[N];int L,R;
bool check(node A,node B,node C){
	int x1=C.x-A.x,y1=C.y-A.y,x2=B.x-A.x,y2=B.y-A.y;
	return x1*x2+y1*y2>0; 
}
//bool check(node A,node B,node C){
//	return (B.y-A.y)*(C.x-B.x)>(C.y-B.y)*(B.x-A.x);
//}
signed main(){
	n=read(),mp[1]=0;
	For(i,1,n){
		int u=read(),v=read(),x=read();
		mp[u]+=x,mp[v]+=x,sum-=2*x;
	}for(auto x:mp)c++,id[c]=x.fi*2,sum+=2*x.se,val[c]=sum;
	int ans=-1e18;
//	For(i,1,c)For(j,i,c)ans=max(ans,val[i]+val[j]-id[i]*id[j]);
	L=1,R=0;For(i,1,c){
		ans=max(ans,2*val[i]-id[i]*id[i]);
		while(L<R&&q[L].val(-id[i])<=q[L+1].val(-id[i]))L++;
		if(L<=R)ans=max(ans,val[i]+q[L].val(-id[i]));
		node now=(node){id[i],val[i]};
		while(L<R&&!check(q[R-1],q[R],now))R--;
		q[++R]=now;
	}
	cout<<1.0*ans/4<<endl;
	return 0;
}

詳細信息

Test #1:

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

input:

2
1 4 15
3 5 10

output:

2.5

result:

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

Test #2:

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

input:

1
2 2 8

output:

4

result:

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

Test #3:

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

input:

3
94 68 49
51 2 63
26 85 20

output:

-73

result:

ok found '-73.0000000', expected '-73.0000000', error '-0.0000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 7784kb

input:

2
14 68 12
28 2 46

output:

-16

result:

ok found '-16.0000000', expected '-16.0000000', error '-0.0000000'

Test #5:

score: 0
Accepted
time: 3ms
memory: 9768kb

input:

5
6 6 8
6 1 11
6 1 13
6 1 5
5 1 2

output:

9.5

result:

ok found '9.5000000', expected '9.5000000', error '0.0000000'

Test #6:

score: 0
Accepted
time: 3ms
memory: 7724kb

input:

5
5 4 2
4 1 10
3 1 3
2 1 3
5 1 5

output:

5.5

result:

ok found '5.5000000', expected '5.5000000', error '0.0000000'

Test #7:

score: 0
Accepted
time: 3ms
memory: 7808kb

input:

5
1 5 2
4 2 7
2 2 2
2 5 14
1 4 2

output:

4.5

result:

ok found '4.5000000', expected '4.5000000', error '0.0000000'

Test #8:

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

input:

5
4 1 9
1 5 13
3 6 10
6 5 8
3 5 5

output:

9

result:

ok found '9.0000000', expected '9.0000000', error '0.0000000'

Test #9:

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

input:

5
3 7 9
5 7 12
4 6 13
3 6 6
2 1 2

output:

-6

result:

ok found '-6.0000000', expected '-6.0000000', error '-0.0000000'

Test #10:

score: 0
Accepted
time: 3ms
memory: 7796kb

input:

10
8 10 26
11 2 28
13 4 13
11 1 26
6 15 23
12 8 7
9 8 11
11 10 17
8 11 18
3 10 27

output:

32

result:

ok found '32.0000000', expected '32.0000000', error '0.0000000'

Test #11:

score: 0
Accepted
time: 0ms
memory: 7852kb

input:

10
6 5 10
10 15 21
7 2 30
14 6 12
1 11 6
1 13 19
8 13 29
9 4 14
1 4 29
4 12 17

output:

12

result:

ok found '12.0000000', expected '12.0000000', error '0.0000000'

Test #12:

score: -100
Wrong Answer
time: 0ms
memory: 7932kb

input:

10
5 15 15
3 14 20
11 14 26
15 12 22
5 15 11
12 10 10
1 12 18
7 7 14
3 5 10
12 9 23

output:

-33

result:

wrong answer 1st numbers differ - expected: '-6.0000000', found: '-33.0000000', error = '4.5000000'