結果

問題 No.461 三角形はいくつ?
ユーザー chaemonchaemon
提出日時 2016-12-12 00:51:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,001 ms / 5,000 ms
コード長 3,627 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 98,456 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-06 19:04:45
合計ジャッジ時間 32,695 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 5 ms
6,944 KB
testcase_05 AC 902 ms
6,940 KB
testcase_06 AC 493 ms
6,940 KB
testcase_07 AC 606 ms
6,940 KB
testcase_08 AC 408 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 128 ms
6,944 KB
testcase_11 AC 688 ms
6,940 KB
testcase_12 AC 310 ms
6,940 KB
testcase_13 AC 1,011 ms
6,940 KB
testcase_14 AC 979 ms
6,940 KB
testcase_15 AC 1,038 ms
6,944 KB
testcase_16 AC 703 ms
6,944 KB
testcase_17 AC 742 ms
6,940 KB
testcase_18 AC 954 ms
6,944 KB
testcase_19 AC 968 ms
6,944 KB
testcase_20 AC 1,073 ms
6,940 KB
testcase_21 AC 1,030 ms
6,940 KB
testcase_22 AC 1,013 ms
6,944 KB
testcase_23 AC 551 ms
6,940 KB
testcase_24 AC 557 ms
6,940 KB
testcase_25 AC 2,001 ms
6,940 KB
testcase_26 AC 1,992 ms
6,940 KB
testcase_27 AC 6 ms
6,944 KB
testcase_28 AC 6 ms
6,944 KB
testcase_29 AC 1,902 ms
6,944 KB
testcase_30 AC 1,997 ms
6,944 KB
testcase_31 AC 1,712 ms
6,940 KB
testcase_32 AC 1,590 ms
6,940 KB
testcase_33 AC 7 ms
6,940 KB
testcase_34 AC 7 ms
6,944 KB
testcase_35 AC 6 ms
6,944 KB
testcase_36 AC 566 ms
6,944 KB
testcase_37 AC 557 ms
6,940 KB
testcase_38 AC 546 ms
6,940 KB
testcase_39 AC 560 ms
6,944 KB
testcase_40 AC 565 ms
6,940 KB
testcase_41 AC 579 ms
6,940 KB
testcase_42 AC 649 ms
6,940 KB
testcase_43 AC 621 ms
6,944 KB
testcase_44 AC 679 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
#ifdef __MINGW32__
typedef double rn;
#else
typedef long double rn;
#endif

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

//{{{ quatient class
Int gcd(Int a, Int b) { return a > 0 ? gcd(b % a, a) : b; }
struct F {
	Int p, q;
	void normalize() { // keep q positive
		if (q < 0) p *= -1, q *= -1;
		Int d = gcd(p < 0 ? -p : p, q);
		if (d == 0) p = 0,  q = 1;
		else        p /= d, q /= d;
	}
	F(Int p, Int q = 1) : p(p), q(q) {
		normalize();
	}
	F &operator += (const F &a) {
		p = a.q * p + a.p * q; q = a.q * q;
		return *this;
	}
	F &operator -= (const F &a) {
		p = a.q * p - a.p * q; q = a.q * q;
		return *this;
	}
	F &operator *= (const F &a) {
		p *= a.p; q *= a.q;
		return *this;
	}
	F &operator /= (const F &a) {
		p *= a.q; q *= a.p;
		return *this;
	}
	F &operator - () {
		p *= -1;
		return *this;
	}
};
F operator + (const F &a, const F &b) {
	return F(a) += b;
}
F operator * (const F &a, const F &b) {
	return F(a) *= b;
}
F operator - (const F &a, const F &b) {
	return F(a) -= b;
}
F operator / (const F &a, const F &b) {
	return F(a) /= b;
}
bool operator < (const F &a, const F &b) { // avoid overflow
	return a.p * b.q < a.q * b.p;
}
bool operator <= (const F &a, const F &b) {
	return !(b < a);
}
bool operator > (const F &a, const F &b) {
	return b < a;
}
bool operator >= (const F &a, const F &b) {
	return !(a < b);
}
bool operator == (const F &a, const F &b) {
	return !(a < b) && !(b < a);
}
bool operator != (const F &a, const F &b) {
	return (a < b) || (b < a);
}
//}}}

int N;
vector<F> t[3];
vector<F> listed;

int main(){
	cin>>N;
	REP(i,3)t[i].push_back(1.0L);
	listed.push_back(1.0L);
	REP(i,N){
		int p,a,b;
		cin>>p>>a>>b;
		t[p].push_back(F(a,a+b));
		if(p==2)listed.push_back(t[p].back());
	}
	sort(ALL(listed));
	Int d = 0;
	REP(i,t[0].size())REP(j,t[1].size()){
		F u = F(2)-(t[0][i] + t[1][j]);
		u.normalize();
		d+=distance(lower_bound(ALL(listed),u),upper_bound(ALL(listed),u));
	}
	Int ans = 0;
	REP(i,t[0].size())REP(j,t[1].size()){
		if(t[0][i]+t[1][j]<F(1))continue;
		F u = max(F(1)-t[0][i],F(1)-t[1][j]);
		u.normalize();
		
		Int k = distance(lower_bound(ALL(listed),u),listed.end());
//		cout<<t[0][i]<<" "<<t[1][j]<<" "<<u<<" "<<k<<endl;
		ans+=k;
	}
//	cout<<ans<<" "<<d<<endl;
//	cout<<ans<<endl;
	cout<<ans-d<<endl;
	return 0;
}
0