結果

問題 No.461 三角形はいくつ?
ユーザー ヒッキープログラミングするスレ GitHub ガチヒッキープログラミングするスレ GitHub ガチ
提出日時 2016-12-12 06:45:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,232 bytes
コンパイル時間 3,621 ms
コンパイル使用メモリ 69,168 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 19:56:02
合計ジャッジ時間 4,763 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 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 73 ms
4,384 KB
testcase_06 AC 41 ms
4,376 KB
testcase_07 AC 49 ms
4,380 KB
testcase_08 AC 34 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 11 ms
4,384 KB
testcase_11 AC 55 ms
4,376 KB
testcase_12 AC 25 ms
4,376 KB
testcase_13 AC 83 ms
4,380 KB
testcase_14 AC 78 ms
4,376 KB
testcase_15 AC 83 ms
4,384 KB
testcase_16 AC 5 ms
4,384 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 81 ms
4,380 KB
testcase_21 AC 84 ms
4,380 KB
testcase_22 AC 85 ms
4,384 KB
testcase_23 AC 12 ms
4,376 KB
testcase_24 AC 12 ms
4,376 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 19 ms
4,380 KB
testcase_30 AC 11 ms
4,384 KB
testcase_31 AC 33 ms
4,376 KB
testcase_32 AC 42 ms
4,384 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 5 ms
4,380 KB
testcase_35 AC 4 ms
4,380 KB
testcase_36 AC 19 ms
4,376 KB
testcase_37 AC 19 ms
4,380 KB
testcase_38 AC 19 ms
4,380 KB
testcase_39 AC 18 ms
4,376 KB
testcase_40 AC 19 ms
4,380 KB
testcase_41 AC 21 ms
4,380 KB
testcase_42 AC 76 ms
4,380 KB
testcase_43 AC 77 ms
4,380 KB
testcase_44 AC 78 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

template <typename T>
T gcd(T x, T y) {
    T z; while (x) { z = x; x = y % x; y = z; } return y;
}

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 sfun(const void* p, const void* q) {
    return ((std::vector<rational<long long> >*)p)->size() - ((std::vector<rational<long long> >*)q)->size();
}

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;
        int g = gcd(a, a + b);
        ps[p].push_back({a / g, (a + b) / g});
    }
    
    for (auto i = 0; i < 3; i++) {
        ps[i].push_back({1, 1});
        std::sort(ps[i].begin(), ps[i].end());
    }
    
    qsort(ps, sizeof(ps)/sizeof(ps[0]), sizeof(ps[0]), sfun);
    
    auto &p0 = ps[0], &p1 = ps[1], &p2 = ps[2];
    auto ans = 0;
    
    for (auto it0 = p0.begin(); it0 != p0.end(); it0++) {
        auto x = *it0, dx = x.diff1();
        for (auto it1 = std::lower_bound(p1.begin(), p1.end(), dx); it1 != p1.end(); it1++) {
            auto y = *it1, dy = y.diff1();
            auto it2 = std::lower_bound(p2.begin(), p2.end(), std::min(x, y).diff1());
            ans += (p2.end() - it2) - 1;
            if ((x - dy).a) {
                auto r = dx + dy;
                auto cr = std::lower_bound(it2, p2.end(), r);
                if ((r - *cr).a) {
                    ans++;
                }
            }
        }
    }
    
    std::cout << ans << std::endl;
    
    
    return 0;
}
0