結果

問題 No.461 三角形はいくつ?
ユーザー PachicobuePachicobue
提出日時 2018-09-15 16:10:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,939 bytes
コンパイル時間 2,398 ms
コンパイル使用メモリ 212,496 KB
実行使用メモリ 5,252 KB
最終ジャッジ日時 2023-09-25 07:54:24
合計ジャッジ時間 40,458 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,252 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 13 ms
4,380 KB
testcase_05 AC 4,104 ms
4,376 KB
testcase_06 AC 2,336 ms
4,376 KB
testcase_07 AC 2,740 ms
4,376 KB
testcase_08 AC 1,853 ms
4,380 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 569 ms
4,380 KB
testcase_11 AC 3,087 ms
4,376 KB
testcase_12 AC 1,384 ms
4,376 KB
testcase_13 AC 4,599 ms
4,376 KB
testcase_14 AC 4,332 ms
4,376 KB
testcase_15 AC 4,663 ms
4,380 KB
testcase_16 AC 14 ms
4,376 KB
testcase_17 AC 14 ms
4,380 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{1}, B{1}, C{1};
    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{a, 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::greater<Rational>{}), std::sort(C.begin(), C.end(), std::greater<Rational>{});
    int ans = 0;
    for (const auto& b : B) {
        for (const auto& c : C) {
            if (b + c < Rational(1)) { break; }
            ans += A.end() - std::lower_bound(A.begin(), A.end(), Rational(1) - std::min(b, c));
            ans -= std::upper_bound(A.begin(), A.end(), Rational(2) - b - c) - std::lower_bound(A.begin(), A.end(), Rational(2) - b - c);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}
0