結果

問題 No.461 三角形はいくつ?
ユーザー parukiparuki
提出日時 2016-12-12 12:11:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,284 bytes
コンパイル時間 1,830 ms
コンパイル使用メモリ 180,008 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-07 03:13:40
合計ジャッジ時間 43,577 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 14 ms
5,376 KB
testcase_17 AC 14 ms
5,376 KB
testcase_18 AC 2,837 ms
5,376 KB
testcase_19 AC 2,812 ms
5,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 9 ms
5,376 KB
testcase_26 AC 9 ms
5,376 KB
testcase_27 AC 9 ms
5,376 KB
testcase_28 AC 9 ms
5,376 KB
testcase_29 AC 2,116 ms
5,376 KB
testcase_30 AC 1,860 ms
5,376 KB
testcase_31 AC 2,532 ms
5,376 KB
testcase_32 AC 2,741 ms
5,376 KB
testcase_33 AC 4 ms
5,376 KB
testcase_34 AC 4 ms
5,376 KB
testcase_35 AC 4 ms
5,376 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

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;

long long gcd(long long a, long long b){
    return b?gcd(b, a%b):a;
}

long long lcm(long long a, long long b){
    return a*b/gcd(a,b);
}

bool les(pair<ll, ll> a, pair<ll, ll> b) {
    // a.f/a.s < b.f/b.s
    // a.f*b.s < b.f * a.s
    return a.first*b.second < b.first*a.second;
}

void adjust(ll &a1, ll &b1, ll &a2, ll &b2) {
    ll s1 = a1 + b1;
    ll s2 = a2 + b2;
    ll l = lcm(s1, s2);
    a1 *= l / s1;
    b1 *= l / s1;
    a2 *= l / s2;
    b2 *= l / s2;
}

bool check(ll a1, ll b1, ll b2, ll a3, ll b3) {
    return a3*(a1 - b2) > b3*(b1 + b2);
}

bool check2(ll a1, ll b1, ll a2, ll b2, ll a3, ll b3) {
    return a1*a3 >= b1*b2 && a2*a3 >= b2*b3;
}

bool check3(ll a1, ll b1, ll b2, ll a3, ll b3) {
    return a3*(a1 - b2) < b3*(b1 + b2);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;

    ll a1, a2, a3, b1, b2, b3;

    // (1) もとの三角形
    ll ans = 1;
    // (2) 追加辺ともとの三角形
    ans += N;
    vll P(N), A(N), B(N);
    vector<vector<pair<ll, ll>>> p2ab(3);

    rep(i, N) {
        cin >> P[i] >> A[i] >> B[i];
        ll g = gcd(A[i], B[i]);
        A[i] /= g;
        B[i] /= g;
        p2ab[P[i]].push_back(mp(A[i], B[i]));
    }

    rep(i, 3)sort(all(p2ab[i]));

    // (3) もとの三角形+追加辺*1
    rep(i, 3) {
        each(p, p2ab[i]) {
            each(q, p2ab[(i + 1) % 3]) {
                tie(a1, b1) = p;
                tie(a2, b2) = q;
                if(a1*a2>b1*b2) {
                    ans++;
                }
            }
        }
    }

    // (4) 追加3辺(上向き)
    if(sz(p2ab[2])) each(p, p2ab[0]) {
        each(q, p2ab[1]) {
            tie(a1, b1) = p;
            tie(a2, b2) = q;
            if(a1*a2>b1*b2) {
                adjust(a1, b1, a2, b2);
                int lb = -1, ub = sz(p2ab[2]) - 1, m;
                tie(a3, b3) = p2ab[2][ub];
                if(!check(a1, b1, b2, a3, b3))continue;
                while(ub - lb > 1) {
                    m = (ub + lb) / 2;
                    tie(a3, b3) = p2ab[2][m];
                    (check(a1, b1, b2, a3, b3) ? ub : lb) = m;
                }
                ans += sz(p2ab[2]) - ub;
            }
        }
    }

    // (5) 追加3辺(下向き)
    if(sz(p2ab[2])) each(p, p2ab[0]) {
        each(q, p2ab[1]) {
            tie(a1, b1) = p;
            tie(a2, b2) = q;
            if(a1*a2 >= b1*b2) {
                adjust(a1, b1, a2, b2);
                
                each(r, p2ab[2]) {
                    tie(a3, b3) = r;
                    if(check2(a1, b1, a2, b2, a3, b3) && check3(a1, b1, b2, a3, b3)) {
                        ++ans;
                    }
                }
            }
        }
    }

    cout << ans << endl;
}
0