QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#102221#4368. Oilfzj2007WA 231ms3456kbC++142.4kb2023-05-02 16:15:222023-05-02 16:15:23

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-02 16:15:23]
  • 评测
  • 测评结果:WA
  • 用时:231ms
  • 内存:3456kb
  • [2023-05-02 16:15:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace IO{
	template<typename T>inline bool read(T &x){
		x=0;
		char ch=getchar();
		bool flag=0,ret=0;
		while(ch<'0'||ch>'9') flag=flag||(ch=='-'),ch=getchar();
		while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(),ret=1;
		x=flag?-x:x;
        return ret;
	}
	template<typename T,typename ...Args>inline bool read(T& a,Args& ...args){
	    return read(a)&&read(args...);
	}
	template<typename T>void prt(T x){
		if(x>9) prt(x/10);
		putchar(x%10+'0');
	}
	template<typename T>inline void put(T x){
		if(x<0) putchar('-'),x=-x;
		prt(x);
	}
	template<typename T>inline void put(char ch,T x){
		if(x<0) putchar('-'),x=-x;
		prt(x);
		putchar(ch);
	}
	template<typename T,typename ...Args>inline void put(T a,Args ...args){
	    put(a);
		put(args...);
	}
	template<typename T,typename ...Args>inline void put(const char ch,T a,Args ...args){
	    put(ch,a);
		put(ch,args...);
	}
	inline void put(string s){
		for(int i=0,sz=s.length();i<sz;i++) putchar(s[i]);
	}
	inline void put(const char* s){
		for(int i=0,sz=strlen(s);i<sz;i++) putchar(s[i]);
	}
}
using namespace IO;
#define N 4005 
#define ll long long
struct Line{
	int l,r,h;
}p[N];
struct node{
	int dx,dy,id;
	node(int _dx=0,int _dy=0,int _id=0):dx(_dx),dy(_dy),id(_id){}
	inline bool operator<(const node &b)const{
		return (ll)dx*b.dy<(ll)b.dx*dy;
	}
	inline bool operator==(const node &b)const{
		return (ll)dx*b.dy==(ll)dy*b.dx;
	}
}t[N];
int n,vis[N];
ll ans;
inline ll solve(int x,int y){
	memset(vis,0,sizeof(vis));
	ll res=0;int m=0;
	for(int i=1;i<=n;i++){
		if(p[i].h==y) continue;
		t[++m]=node(p[i].h-y,p[i].l-x,i);
		t[++m]=node(p[i].h-y,p[i].r-x,i);
	}
	sort(t+1,t+m+1);
	ll val=0;
	for(int i=1;i<=m;){
		int j=i;ll del=0;
		if(!vis[t[j].id]) val+=p[t[j].id].r-p[t[j].id].l,vis[t[j].id]=1; 
		else del+=p[t[j].id].r-p[t[j].id].l;
		while(j+1<=m&&t[j]==t[j+1]){
			j++;
			if(!vis[t[j].id]) val+=p[t[j].id].r-p[t[j].id].l,vis[t[j].id]=1; 
			else del+=p[t[j].id].r-p[t[j].id].l;
		}
		res=max(res,val),val-=del;
		i=j+1;
	}
	return res;
}
int main(){
	read(n);
	for(int i=1;i<=n;i++){
		read(p[i].l,p[i].r,p[i].h);
		if(p[i].l>p[i].r) swap(p[i].l,p[i].r);
	}
	for(int i=1;i<=n;i++) 
		ans=max(ans,p[i].r-p[i].l+max(solve(p[i].l,p[i].h),solve(p[i].r,p[i].h)));
	put('\n',ans);	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3444kb

input:

5
100 180 20
30 60 30
70 110 40
10 40 50
0 80 70

output:

200

result:

ok single line: '200'

Test #2:

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

input:

3
50 60 10
-42 -42 20
25 0 10

output:

25

result:

ok single line: '25'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3440kb

input:

1
-100 180 20

output:

280

result:

ok single line: '280'

Test #4:

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

input:

1
-1000000 1000000 1

output:

2000000

result:

ok single line: '2000000'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3380kb

input:

1
-1000000 1000000 1000000

output:

2000000

result:

ok single line: '2000000'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3284kb

input:

1
-1000000 -999999 1000000

output:

1

result:

ok single line: '1'

Test #7:

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

input:

1
1000000 999999 1000000

output:

1

result:

ok single line: '1'

Test #8:

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

input:

2
-1000 0 200
1 1000 200

output:

1000

result:

ok single line: '1000'

Test #9:

score: -100
Wrong Answer
time: 231ms
memory: 3344kb

input:

1000
737368 429284 959063
-548693 513523 43074
243164 -465669 860567
422975 -244747 588631
-136535 -470055 501433
-580596 -269833 22422
476738 -448258 866889
358773 563858 950905
-923261 208187 66835
-295330 444422 360513
-903435 841952 491761
377801 520064 65247
479135 -307498 426574
-794533 -46924...

output:

489404789

result:

wrong answer 1st lines differ - expected: '490622362', found: '489404789'