結果
| 問題 |
No.461 三角形はいくつ?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-12 05:30:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,804 bytes |
| コンパイル時間 | 1,898 ms |
| コンパイル使用メモリ | 67,252 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-29 15:05:20 |
| 合計ジャッジ時間 | 5,205 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 12 WA * 29 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
template <typename T>
struct rational {
T a, b;
rational():a(0),b(1) {}
rational(T _a):a(_a),b(1) {}
rational(T _a, T _b):a(_a),b(_b) {}
rational<T> operator +(const rational<T> o) const {
return b == o.b ? rational<T>(a + o.a, b) : rational<T>(a * o.b + o.a * b, b * o.b);
}
rational<T> operator -(const rational<T> o) const {
return b == o.b ? rational<T>(a - o.a, b) : rational<T>(a * o.b - o.a * b, b * o.b);
}
bool operator <(const rational<T> o) const {
return b == o.b ? a < o.a : a * o.b < o.a * b;
}
rational<T> diff1() const { return rational<T>(b - a, b); }
};
int main() {
using std::vector;
typedef rational<long long> rational;
int n;
vector<rational> ps[3];
std::cin >> n;
for (auto i = 0; i < n; i++) {
int p, a, b;
std::cin >> p >> a >> b;
ps[p].push_back({a, a + b});
}
for (auto i = 0; i < 3; i++) {
ps[i].push_back({1, 1});
std::sort(ps[i].begin(), ps[i].end());
}
auto ans = 0;
for (auto it0 = ps[0].begin(); it0 != ps[0].end(); it0++) {
auto x = *it0, dx = x.diff1();
for (auto it1 = ps[1].begin(); it1 != ps[1].end(); it1++) {
auto y = *it1, dy = y.diff1();
auto it2 = std::lower_bound(ps[2].begin(), ps[2].end(), std::min(x, y).diff1());
ans += (ps[2].end() - it2) - 1;
if ((x - dy).a) {
auto r = dx + dy;
auto cr = std::lower_bound(ps[2].begin(), ps[2].end(), r);
if ((r - *cr).a) {
ans++;
}
}
}
}
std::cout << ans << std::endl;
return 0;
}