結果

問題 No.461 三角形はいくつ?
ユーザー parukiparuki
提出日時 2016-12-13 15:57:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 313 ms / 5,000 ms
コード長 1,827 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 176,832 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 01:56:02
合計ジャッジ時間 6,934 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 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 108 ms
4,376 KB
testcase_06 AC 57 ms
4,380 KB
testcase_07 AC 67 ms
4,384 KB
testcase_08 AC 48 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 15 ms
4,380 KB
testcase_11 AC 79 ms
4,380 KB
testcase_12 AC 37 ms
4,376 KB
testcase_13 AC 121 ms
4,376 KB
testcase_14 AC 113 ms
4,380 KB
testcase_15 AC 121 ms
4,380 KB
testcase_16 AC 12 ms
4,376 KB
testcase_17 AC 11 ms
4,380 KB
testcase_18 AC 208 ms
4,376 KB
testcase_19 AC 213 ms
4,380 KB
testcase_20 AC 122 ms
4,380 KB
testcase_21 AC 118 ms
4,380 KB
testcase_22 AC 117 ms
4,380 KB
testcase_23 AC 25 ms
4,376 KB
testcase_24 AC 23 ms
4,384 KB
testcase_25 AC 8 ms
4,376 KB
testcase_26 AC 8 ms
4,380 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 303 ms
4,376 KB
testcase_30 AC 281 ms
4,380 KB
testcase_31 AC 309 ms
4,376 KB
testcase_32 AC 313 ms
4,376 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 41 ms
4,380 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 38 ms
4,380 KB
testcase_41 AC 39 ms
4,380 KB
testcase_42 AC 112 ms
4,380 KB
testcase_43 AC 117 ms
4,376 KB
testcase_44 AC 111 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;

bool les(pll x, pll y) {
    return x.first*y.second < y.first*x.second;
}

bool f(pll x, pll y) {
    return x.first*y.second + x.second*y.first <= x.second*y.second;
}

bool g(pll x, pll y) {
    return x.first*y.second + x.second*y.first < x.second*y.second;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vi p(N), a(N), b(N);
    rep(i, N)cin >> p[i] >> a[i] >> b[i];

    vector<vector<pll>> vv(3);
    rep(i, N) {
        vv[p[i]].push_back(mp(b[i], a[i] + b[i]));
    }
    rep(i, 3)sort(all(vv[i]), les);

    ll ans = N + 1;
    if(sz(vv[0])*sz(vv[1])*sz(vv[2])) each(s, vv[0]) {
        each(t, vv[1]) if(f(s, t) && f(s,vv[2][0]) && f(t, vv[2][0])){
            int lb = 0, ub = sz(vv[2]), m;
            while(ub - lb > 1) {
                m = (lb + ub) >> 1;
                ((f(s, vv[2][m]) && f(t, vv[2][m])) ? lb : ub) = m;
            }
            ll d = s.second*t.second;
            pll ng(d - s.first*t.second - t.first*s.second, d);
            ans += ub;
            if(binary_search(vv[2].begin(), vv[2].begin()+ub, ng, les))
                --ans;
        }
    }

    rep(i, 3) {
        int j = (i + 1) % 3;
        each(s, vv[i])each(t, vv[j])if(g(s, t))ans++;
    }

    cout << ans << endl;
}
0