結果

問題 No.461 三角形はいくつ?
ユーザー pekempeypekempey
提出日時 2016-12-12 01:24:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 170 ms / 5,000 ms
コード長 1,661 bytes
コンパイル時間 3,855 ms
コンパイル使用メモリ 185,556 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 12:48:56
合計ジャッジ時間 7,169 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 151 ms
4,376 KB
testcase_06 AC 79 ms
4,384 KB
testcase_07 AC 97 ms
4,380 KB
testcase_08 AC 65 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 20 ms
4,376 KB
testcase_11 AC 110 ms
4,380 KB
testcase_12 AC 49 ms
4,376 KB
testcase_13 AC 167 ms
4,376 KB
testcase_14 AC 156 ms
4,380 KB
testcase_15 AC 166 ms
4,376 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 103 ms
4,376 KB
testcase_19 AC 105 ms
4,380 KB
testcase_20 AC 170 ms
4,376 KB
testcase_21 AC 160 ms
4,380 KB
testcase_22 AC 161 ms
4,376 KB
testcase_23 AC 24 ms
4,380 KB
testcase_24 AC 22 ms
4,380 KB
testcase_25 AC 58 ms
4,376 KB
testcase_26 AC 57 ms
4,380 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 5 ms
4,376 KB
testcase_29 AC 162 ms
4,376 KB
testcase_30 AC 155 ms
4,380 KB
testcase_31 AC 162 ms
4,380 KB
testcase_32 AC 159 ms
4,380 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 4 ms
4,376 KB
testcase_35 AC 5 ms
4,380 KB
testcase_36 AC 41 ms
4,384 KB
testcase_37 AC 36 ms
4,380 KB
testcase_38 AC 38 ms
4,376 KB
testcase_39 AC 34 ms
4,380 KB
testcase_40 AC 40 ms
4,380 KB
testcase_41 AC 39 ms
4,380 KB
testcase_42 AC 126 ms
4,376 KB
testcase_43 AC 120 ms
4,380 KB
testcase_44 AC 128 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
using namespace std;

struct Fraction {
    int64_t a, b;

    Fraction(int64_t a, int64_t b) : a(a), b(b) {}
};

bool operator<(const Fraction &l, const Fraction &r) {
    return l.a * r.b < l.b * r.a;
}

Fraction operator+(const Fraction &l, const Fraction &r) {
    return Fraction(l.a * r.b + r.a * l.b, l.b * r.b);
}

Fraction operator-(const Fraction &l, const Fraction &r) {
    return Fraction(l.a * r.b - r.a * l.b, l.b * r.b);
}

bool operator==(const Fraction &l, const Fraction &r) {
    return l.a * r.b == r.a * l.b;
}

int main() {
    int n;
    cin >> n;
    vector<vector<Fraction>> f(3);
    for (int i = 0; i < 3; i++) {
        f[i].emplace_back(1, 1);
    }
    for (int i = 0; i < n; i++) {
        int p, ta, tb;
        cin >> p >> ta >> tb;
        f[p].emplace_back(ta, ta + tb);
    }
    sort(f[2].begin(), f[2].end());
    int64_t ans = 0;
    for (int i = 0; i < f[0].size(); i++) {
        for (int j = 0; j < f[1].size(); j++) {
            if (f[0][i] + f[1][j] < Fraction(1, 1)) {
                continue;
            }
            int k0 = lower_bound(f[2].begin(), f[2].end(), Fraction(1, 1) - f[0][i]) - f[2].begin();
            int k1 = lower_bound(f[2].begin(), f[2].end(), Fraction(1, 1) - f[1][j]) - f[2].begin();
            int k2 = lower_bound(f[2].begin(), f[2].end(), Fraction(2, 1) - f[0][i] - f[1][j]) - f[2].begin();
            if (k2 < f[2].size() && f[0][i] + f[1][j] + f[2][k2] == Fraction(2, 1)) {
                ans--;
            }
            ans += f[2].size() - max(k0, k1);
        }
    }
    cout << ans << endl;
}
0