結果

問題 No.461 三角形はいくつ?
ユーザー tubo28
提出日時 2016-12-12 15:50:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,106 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 173,524 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-29 16:10:39
合計ジャッジ時間 11,527 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

using ld = __float128;

int n;
vector<ld> ls[3];

int main(){
	while(cin >> n){
		for(int i = 0; i < 3; ++i) ls[i].clear();
		rep(i, n){
			int p;
			int a, b;
			cin >> p >> a >> b;
			int g = __gcd(a, b);
			a /= g;
			b /= g;
			ls[p].push_back((ld)a / (a + b));
		}
		for(int i = 0; i < 3; ++i) sort(all(ls[i]));

		// 1本
		ll ans = n + 1;
		
		for(auto &x : ls[1]){
			x = 1 - x;
			ans += ls[0].end() - upper_bound(all(ls[0]), x);
		}
		for(auto &y : ls[2]){
			y = 1 - y;
			ans += ls[0].end() - upper_bound(all(ls[0]), y);
		}

		for(ld x : ls[1]){
			for(ld y : ls[2]){
				if(x + y < 1){
					// 2本 (1,2)
					++ans;
				}
				if(x + y <= 1 + 1e-10){
					// 3本 (0,1,2)
					int a = lower_bound(all(ls[0]), x + y) - lower_bound(all(ls[0]), max(x, y));
					int b = ls[0].end() - upper_bound(all(ls[0]), x + y);
					ans += a + b;
				}
			}
		}
		cout << ans << endl;
	}
}
0