結果

問題 No.461 三角形はいくつ?
ユーザー FF256grhyFF256grhy
提出日時 2016-12-12 02:53:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 91 ms / 5,000 ms
コード長 2,897 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 53,824 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-19 18:43:42
合計ジャッジ時間 6,461 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 73 ms
4,384 KB
testcase_06 AC 42 ms
4,384 KB
testcase_07 AC 50 ms
4,384 KB
testcase_08 AC 34 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 11 ms
4,384 KB
testcase_11 AC 58 ms
4,380 KB
testcase_12 AC 25 ms
4,380 KB
testcase_13 AC 85 ms
4,380 KB
testcase_14 AC 86 ms
4,384 KB
testcase_15 AC 84 ms
4,388 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 7 ms
4,384 KB
testcase_18 AC 91 ms
4,380 KB
testcase_19 AC 88 ms
4,380 KB
testcase_20 AC 81 ms
4,380 KB
testcase_21 AC 84 ms
4,380 KB
testcase_22 AC 84 ms
4,384 KB
testcase_23 AC 13 ms
4,384 KB
testcase_24 AC 13 ms
4,380 KB
testcase_25 AC 3 ms
4,384 KB
testcase_26 AC 3 ms
4,384 KB
testcase_27 AC 46 ms
4,384 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 20 ms
4,380 KB
testcase_30 AC 11 ms
4,380 KB
testcase_31 AC 38 ms
4,384 KB
testcase_32 AC 48 ms
4,384 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 20 ms
4,384 KB
testcase_37 AC 22 ms
4,380 KB
testcase_38 AC 21 ms
4,384 KB
testcase_39 AC 19 ms
4,380 KB
testcase_40 AC 21 ms
4,384 KB
testcase_41 AC 22 ms
4,380 KB
testcase_42 AC 71 ms
4,380 KB
testcase_43 AC 71 ms
4,380 KB
testcase_44 AC 72 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cmath>

#include <vector>
#include <utility>
#include <algorithm>

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

// template<typename T> void swap(T & x, T & y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

struct Frac {
	LL p, q;
	Frac(LL pp, LL qq) { p = pp; q = qq; }
	bool operator<(const Frac & obj) const {
		return (this -> p) * (obj.q) <  (obj.p) * (this -> q);
	}
	bool operator==(const Frac & obj) const {
		return (this -> p) * (obj.q) == (obj.p) * (this -> q);
	}
	double val() { return static_cast<double>(p) / q; }
};

int n, p[4000], a[4000], b[4000];
LL ans;
std::vector<Frac> vec[3];

int main() {
	scanf("%d", &n);
	inc(i, n) { scanf("%d%d%d", &p[i], &a[i], &b[i]); }
	
	inc(i, n) { Frac f(a[i], a[i] + b[i]); vec[ p[i] ].push_back(f); }
	inc(i, 3) { Frac f(1, 1);              vec[   i  ].push_back(f); }
	
	inc(i, 3) { std::sort(vec[i].begin(), vec[i].end()); }
	
	/*
	inc(i, 3) {
		for(auto && e: vec[i]) { printf("%2d/%2d = %.2f\n", e.p, e.q, e.val()); }
		printf("\n");
	}
	*/
	
	for(auto && e1: vec[1]) {
	for(auto && e2: vec[2]) {
		// printf("e1: <%2d,%4d>, e2: <%2d,%4d>,  ", e1.p, e1.q, e2.p, e2.q);
		
		Frac x(e1.q - e1.p, e1.q);
		Frac y(e2.q - e2.p, e2.q);
		Frac z((e1.q - e1.p) * e2.q + (e2.q - e2.p) * e1.q, e1.q * e2.q);
		Frac u(1, 1);
		if(u < z) { continue; }
		if(y < x) { std::swap(x, y); }
		
		auto lby = std::lower_bound(vec[0].begin(), vec[0].end(), y);
		auto lbz = std::lower_bound(vec[0].begin(), vec[0].end(), z);
		int v = vec[0].end() - lby, w = (lbz != vec[0].end() && *(lbz) == z);
		ans += v - w;
		
		/*
		// printf("x: <%2d,%2d>, y: <%2d,%2d>, z: <%2d,%2d>,   ", x.p, x.q, y.p, y.q, z.p, z.q );
		printf("x: [%.2f], y: [%.2f], z: [%.2f],  ", x.val(), y.val(), z.val());
		printf("ans += %d -  %d\n", v, w);
		*/
	}
	}
	
	printf("%lld\n", ans);
	
	return 0;
}
0