結果

問題 No.461 三角形はいくつ?
ユーザー PachicobuePachicobue
提出日時 2018-09-15 20:42:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,889 bytes
コンパイル時間 3,003 ms
コンパイル使用メモリ 209,920 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 08:48:40
合計ジャッジ時間 40,539 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 14 ms
4,376 KB
testcase_05 AC 4,119 ms
4,376 KB
testcase_06 AC 2,336 ms
4,376 KB
testcase_07 AC 2,759 ms
4,376 KB
testcase_08 AC 1,860 ms
4,380 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 570 ms
4,380 KB
testcase_11 AC 3,104 ms
4,380 KB
testcase_12 AC 1,392 ms
4,376 KB
testcase_13 AC 4,628 ms
4,376 KB
testcase_14 AC 4,349 ms
4,376 KB
testcase_15 AC 4,694 ms
4,380 KB
testcase_16 AC 14 ms
4,376 KB
testcase_17 AC 14 ms
4,376 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
template <typename T>
constexpr T gcd(const T a, const T b) { return (b != 0) ? gcd(b, a % b) : a; }
template <typename T>
constexpr T lcm(const T a, const T b) { return (a / gcd(a, b)) * b; }
class Rational
{
public:
    using T = ll;
    Rational() = default;
    Rational(const T N) : N{N} {}
    Rational(const T N_, const T D_) : N{N_}, D{D_} { N /= gcd(N_, D_), D /= gcd(N_, D_); }
    Rational operator+(const Rational& r) const { return Rational{lcm(D, r.D) / D * N + lcm(D, r.D) / r.D * r.N, lcm(D, r.D)}; }
    Rational operator-(const Rational& r) const { return Rational{lcm(D, r.D) / D * N - lcm(D, r.D) / r.D * r.N, lcm(D, r.D)}; }
    bool operator==(const Rational& r) const { return N * r.D == D * r.N; }
    bool operator<(const Rational& r) const { return N * r.D < D * r.N; }
    bool operator>(const Rational& r) const { return N * r.D > D * r.N; }

private:
    T N = 0, D = 1;
};
int main()
{
    int N;
    std::cin >> N;
    std::vector<Rational> A{0}, B{0}, C{0};
    for (int i = 0; i < N; i++) {
        int p, a, b;
        std::cin >> p >> a >> b;
        (p == 0 ? A : p == 1 ? B : C).push_back(Rational{b, a + b});
    }
    if (A.size() < B.size()) { std::swap(A, B); }
    if (A.size() < C.size()) { std::swap(A, C); }
    std::sort(A.begin(), A.end()), std::sort(B.begin(), B.end()), std::sort(C.begin(), C.end());
    int ans = 0;
    for (const auto& b : B) {
        for (const auto& c : C) {
            if (b + c > Rational(1)) { break; }
            ans += std::upper_bound(A.begin(), A.end(), Rational(1) - std::max(b, c)) - A.begin();
            ans -= std::upper_bound(A.begin(), A.end(), Rational(1) - b - c) - std::lower_bound(A.begin(), A.end(), Rational(1) - b - c);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}
0