結果

問題 No.461 三角形はいくつ?
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-20 01:51:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 241 ms / 5,000 ms
コード長 1,631 bytes
コンパイル時間 1,510 ms
コンパイル使用メモリ 170,024 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 15:27:23
合計ジャッジ時間 7,456 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 216 ms
4,380 KB
testcase_06 AC 113 ms
4,380 KB
testcase_07 AC 137 ms
4,380 KB
testcase_08 AC 90 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 25 ms
4,380 KB
testcase_11 AC 157 ms
4,376 KB
testcase_12 AC 69 ms
4,376 KB
testcase_13 AC 241 ms
4,376 KB
testcase_14 AC 219 ms
4,376 KB
testcase_15 AC 241 ms
4,376 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 147 ms
4,376 KB
testcase_19 AC 154 ms
4,376 KB
testcase_20 AC 239 ms
4,380 KB
testcase_21 AC 232 ms
4,376 KB
testcase_22 AC 227 ms
4,380 KB
testcase_23 AC 24 ms
4,380 KB
testcase_24 AC 22 ms
4,376 KB
testcase_25 AC 118 ms
4,380 KB
testcase_26 AC 116 ms
4,376 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 239 ms
4,376 KB
testcase_30 AC 230 ms
4,376 KB
testcase_31 AC 231 ms
4,380 KB
testcase_32 AC 231 ms
4,376 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 46 ms
4,376 KB
testcase_37 AC 41 ms
4,380 KB
testcase_38 AC 44 ms
4,376 KB
testcase_39 AC 37 ms
4,376 KB
testcase_40 AC 45 ms
4,376 KB
testcase_41 AC 43 ms
4,380 KB
testcase_42 AC 152 ms
4,380 KB
testcase_43 AC 147 ms
4,376 KB
testcase_44 AC 153 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




typedef long double ld;
typedef long long ll;
int N;
vector<ld> vec[3];
ld EPS = 1e-18;
//-----------------------------------------------------------------------------------
ll count() {
    ll ans = 0;

    sort(vec[2].begin(), vec[2].end());

    for (ld a : vec[0]) for (ld b : vec[1]) {

        int cnt = 0, _cnt = 0;

        // Naive
        /*for (ld c : vec[2]) {
            ld sum = a + b + c;
            if (abs(1 - sum) < EPS) continue;

            ld ab = a + b;
            ld bc = b + c;
            ld ac = a + c;

            if (ab <= 1 && bc <= 1 && ac <= 1) _cnt++;
        }*/

        // Optimized
        ld ab = a + b;
        if (1 < ab) continue;

        int minus = 0;
        // c = 1 - a - b があるか探す
        int lo = lower_bound(vec[2].begin(), vec[2].end(), 1 - a - b - EPS) - vec[2].begin();
        int up = upper_bound(vec[2].begin(), vec[2].end(), 1 - a - b + EPS) - vec[2].begin();
        if (lo != up) minus = -1;
        // c <= min(1-b,1-a) の個数を探す
        up = upper_bound(vec[2].begin(), vec[2].end(), min(1 - b, 1 - a) + EPS) - vec[2].begin();
        cnt = up + minus;

        //if (_cnt != cnt) printf("eer!\n");

        ans += cnt;
    }

    return ans;
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> N;
    rep(i, 0, 3) vec[i].push_back(0);
    rep(i, 0, N) {
        int P, A, B;
        scanf("%d%d%d", &P, &A, &B);
        vec[P].push_back((ld)B / (ld)(A + B));
    }

    cout << count() << endl;
}
0