結果

問題 No.1144 Triangles
ユーザー chocoruskchocorusk
提出日時 2020-08-01 01:24:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 408 ms / 3,000 ms
コード長 1,961 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 137,132 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 05:27:33
合計ジャッジ時間 7,933 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 407 ms
4,380 KB
testcase_05 AC 408 ms
4,376 KB
testcase_06 AC 407 ms
4,376 KB
testcase_07 AC 406 ms
4,380 KB
testcase_08 AC 407 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 375 ms
4,376 KB
testcase_15 AC 371 ms
4,380 KB
testcase_16 AC 394 ms
4,376 KB
testcase_17 AC 397 ms
4,376 KB
testcase_18 AC 395 ms
4,380 KB
testcase_19 AC 28 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 380 ms
4,376 KB
testcase_23 AC 24 ms
4,376 KB
testcase_24 AC 375 ms
4,380 KB
testcase_25 AC 123 ms
4,376 KB
testcase_26 AC 14 ms
4,376 KB
testcase_27 AC 21 ms
4,376 KB
testcase_28 AC 76 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
vector<P> sort_points(vector<P> v){
	int n=v.size();
	vector<P> p1, p2;
	int z=0;
	for(int i=0; i<n; i++){
		ll x=v[i].first, y=v[i].second;
		if(x==0 && y==0) z++;
		else if(y>0 || (x<0 && y==0)) p2.push_back({x, y});
		else p1.push_back({x, y});
	}
	auto comp=[](P p, P q){ return p.first*q.second>p.second*q.first;};
	sort(p1.begin(), p1.end(), comp);
	sort(p2.begin(), p2.end(), comp);
	vector<P> ret;
	for(auto p:p1) ret.push_back(p);
	//while(z--) ret.push_back({0, 0});
	for(auto p:p2) ret.push_back(p);
	return ret;
}
const ll MOD=1e9+7;
int main()
{
	int n; cin>>n;
	ll x[2020], y[2020];
	for(int i=0; i<n; i++) cin>>x[i]>>y[i];
	ll ans=0;
	for(int i=0; i<n; i++){
		vector<P> v(n);
		for(int j=0; j<n; j++){
			v[j]=P(x[j]-x[i], y[j]-y[i]);
		}
		v=sort_points(v);
		int m=v.size();
		if(m==0) continue;
		ll xs[4020], ys[4020];
		xs[0]=ys[0]=0;
		for(int j=0; j<2*m; j++){
			xs[j+1]=xs[j]+v[j%m].first, ys[j+1]=ys[j]+v[j%m].second;
		}
		auto comp=[&](int l, int r){
			ll z=v[l].first*v[r%m].second-v[l].second*v[r%m].first;
			if(z!=0) return z>0;
			else if(v[l].first*v[r%m].first+v[l].second*v[r%m].second>0) return l<(r%m);
			else return false;
		};
		int r=1;
		for(int l=0; l<m; l++){
			r=max(r, l+1);
			while(r<l+m && comp(l, r)){
				r++;
			}
			ans+=v[l].first*(ys[r]-ys[l])-v[l].second*(xs[r]-xs[l]);
			ans%=MOD;
		}
	}
	cout<<ans*((MOD+1)/3)%MOD<<endl;
	return 0;
}
0