結果

問題 No.461 三角形はいくつ?
ユーザー antaanta
提出日時 2016-12-12 00:39:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 5,000 ms
コード長 2,374 bytes
コンパイル時間 1,704 ms
コンパイル使用メモリ 173,304 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 11:45:35
合計ジャッジ時間 4,226 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 41 ms
4,376 KB
testcase_06 AC 24 ms
4,376 KB
testcase_07 AC 29 ms
4,376 KB
testcase_08 AC 20 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 32 ms
4,376 KB
testcase_12 AC 15 ms
4,380 KB
testcase_13 AC 47 ms
4,376 KB
testcase_14 AC 46 ms
4,380 KB
testcase_15 AC 48 ms
4,376 KB
testcase_16 AC 23 ms
4,380 KB
testcase_17 AC 25 ms
4,380 KB
testcase_18 AC 21 ms
4,376 KB
testcase_19 AC 22 ms
4,376 KB
testcase_20 AC 49 ms
4,376 KB
testcase_21 AC 49 ms
4,376 KB
testcase_22 AC 48 ms
4,380 KB
testcase_23 AC 25 ms
4,376 KB
testcase_24 AC 26 ms
4,380 KB
testcase_25 AC 30 ms
4,376 KB
testcase_26 AC 30 ms
4,380 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 17 ms
4,380 KB
testcase_29 AC 30 ms
4,376 KB
testcase_30 AC 31 ms
4,380 KB
testcase_31 AC 30 ms
4,376 KB
testcase_32 AC 27 ms
4,376 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 27 ms
4,380 KB
testcase_37 AC 27 ms
4,380 KB
testcase_38 AC 27 ms
4,376 KB
testcase_39 AC 27 ms
4,380 KB
testcase_40 AC 27 ms
4,376 KB
testcase_41 AC 29 ms
4,376 KB
testcase_42 AC 27 ms
4,376 KB
testcase_43 AC 27 ms
4,376 KB
testcase_44 AC 28 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

struct Ratio {
	long long num, den;
	Ratio() : num(0), den(1) {}
	Ratio(long long x, long long y) : num(x), den(y) { if(den < 0 || (den == 0 && num < 0)) num = -num, den = -den; }
	bool operator<(const Ratio &that) const { return (ll)num * that.den < (ll)that.num * den; }
	bool operator<=(const Ratio &that) const { return (ll)num * that.den <= (ll)that.num * den; }
	bool operator==(const Ratio &that) const { return (ll)num * that.den == (ll)that.num * den; }
	Ratio operator+(const Ratio &that) const {
		return Ratio(num * that.den + that.num * den, den * that.den);
	}
	Ratio operator-(const Ratio &that) const {
		return Ratio(num * that.den - that.num * den, den * that.den);
	}
};

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<Ratio> segments[3];
		rep(p, 3)
			segments[p].emplace_back(1, 1);
		rep(i, N) {
			int p; int a; int b;
			scanf("%d%d%d", &p, &a, &b);
			segments[p].emplace_back(a, a + b);
		}
		rep(p, 3)
			sort(segments[p].begin(), segments[p].end());
		auto ge1 = [](Ratio a, Ratio b) {
			return (ll)a.num * b.den + (ll)b.num * a.den >= (ll)a.den * b.den;
		};
		ll ans = 0;
		for(auto s : segments[0]) {
			int n = (int)segments[2].size();
			int jR = n;
			int jL = n;
			int j1 = n, j2 = n;
			Ratio val1 = Ratio(1, 1) - s;
			for(; j1 > 0 && val1 <= segments[2][j1 - 1]; -- j1);
			for(auto t : segments[1]) {
				Ratio val = Ratio(2, 1) - (s + t);
				for(; jR > 0 && val < segments[2][jR - 1]; -- jR);
				ans += (int)segments[2].size() - jR;

				Ratio val2 = Ratio(1, 1) - t;
				for(; jL > 0 && val <= segments[2][jL - 1]; -- jL);
				for(; j2 > 0 && val2 <= segments[2][j2 - 1]; -- j2);
				if(Ratio(1, 1) <= s + t) {
					int L = max(j1, j2), R = jL;
					if(L < R)
						ans += R - L;
				}
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}
0