結果

問題 No.2012 Largest Triangle
ユーザー okkuukenkenokkuukenken
提出日時 2022-07-15 22:24:26
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,642 bytes
コンパイル時間 1,536 ms
コンパイル使用メモリ 134,516 KB
実行使用メモリ 8,400 KB
最終ジャッジ日時 2023-09-10 02:54:49
合計ジャッジ時間 6,715 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,384 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,384 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 150 ms
7,916 KB
testcase_17 AC 150 ms
7,792 KB
testcase_18 WA -
testcase_19 AC 151 ms
7,740 KB
testcase_20 AC 150 ms
7,796 KB
testcase_21 AC 149 ms
8,084 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 151 ms
7,748 KB
testcase_25 AC 151 ms
7,928 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 150 ms
7,860 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 151 ms
8,060 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 WA -
testcase_38 AC 2 ms
4,384 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 41 ms
5,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int dx[]={1,0,0,-1},dy[]={0,1,-1,0};
//点を表す構造体
struct Point{
	int x,y;
	Point(double x=0,double y=0):x(x),y(y){};
};
//四則演算
Point operator-(Point p1,Point p2){
	return Point(p1.x-p2.x,p1.y-p2.y);
}
//比較演算
bool operator<(Point p1,Point p2){
	if(p1.x!=p2.x)
		return p1.x<p2.x;
	return p1.y<p2.y;
}
bool operator>(Point p1,Point p2){
	if(p1.y!=p2.y)
		return p1.y<p2.y;
	return p1.x<p2.x;
}
//入出力
istream&operator>>(istream&is,Point&p){
	is>>p.x>>p.y;
	return is;
}
//ベクトルを表す構造体
typedef Point Vector;
//ベクトルのノルム
double norm(Vector a){
	return (ll)a.x*a.x+(ll)a.y*a.y;
}
//内積
ll dot(Vector a,Vector b){
	return(ll)a.x*b.x+(ll)a.y*b.y;
}
//外積
ll cross(Vector a,Vector b){
	return(ll)a.x*b.y-(ll)a.y*b.x;
}
//多角形を表すクラス
typedef vector<Point>Polygon;
//入出力
istream&operator>>(istream&is,Polygon&p){
	for(auto&x:p)
		is>>x;
	return is;
}
//CCW
constexpr int COUNTER_CLOCKWISE=1;
constexpr int CLOCKWISE=-1;
constexpr int ONLINE_BACK=2;
constexpr int ONLINE_FRONT=-2;
constexpr int ON_SEGMENT=0;
int ccw(Point p0,Point p1,Point p2){
	Vector a=p1-p0,b=p2-p0;
	if(cross(a,b)>0)
		return COUNTER_CLOCKWISE;
	if(cross(a,b)<0)
		return CLOCKWISE;
	if(dot(a,b)<0)
		return ONLINE_BACK;
	if(norm(a)<norm(b))
		return ONLINE_FRONT;
	return ON_SEGMENT;
}
//凸包
Polygon andrewScan(Polygon s){
	if(s.size()<=1)
		return s;
	sort(s.begin(),s.end());
	Polygon u,l;
	u.push_back(s[0]);
	u.push_back(s[1]);
	l.push_back(s[s.size()-1]);
	l.push_back(s[s.size()-2]);
	for(int i=2;i<s.size();i++){
		for(int n=u.size();n>=2&&ccw(u[n-2],u[n-1],s[i])!=CLOCKWISE;n--)
			u.pop_back();
		u.push_back(s[i]);
	}
	for(int i=s.size()-3;i>=0;i--){
		for(int n=l.size();n>=2&&ccw(l[n-2],l[n-1],s[i])!=CLOCKWISE;n--)
			l.pop_back();
		l.push_back(s[i]);
	}
	reverse(l.begin(),l.end());
	for(int i=u.size()-2;i>=1;i--)
		l.push_back(u[i]);
	return l;
}
//最遠点対
ll rotatingCalipers(Polygon s){
	s=andrewScan(s);
	int n=s.size();
	if(n<=2)
		return abs(cross(s[0],s[1]));
	int i=0,j=0;
	for(int k=0;k<n;k++){
		if(s[i]<s[k])
			i=k;
		if(s[j]>s[k])
			j=k;
	}
	ll res=0;
	int si=i;
	do{
		res=max(res,cross(s[i],s[j]));
		if(dot(s[(i+1)%n]-s[i],s[(j+1)%n]-s[j])<0)
			i=(i+1)%n;
		else
			j=(j+1)%n;
	}while(i!=si);
	return res;
}
int main(){
	int n;
	cin>>n;
	Polygon g(n);
	cin>>g;
	cout<<rotatingCalipers(g)<<endl;
}
0