結果

問題 No.461 三角形はいくつ?
ユーザー parukiparuki
提出日時 2016-12-12 02:04:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,399 bytes
コンパイル時間 3,024 ms
コンパイル使用メモリ 186,228 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-07 01:00:53
合計ジャッジ時間 24,016 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 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 555 ms
6,944 KB
testcase_17 AC 589 ms
6,940 KB
testcase_18 AC 543 ms
6,940 KB
testcase_19 AC 562 ms
6,944 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1,085 ms
6,944 KB
testcase_26 AC 1,107 ms
6,944 KB
testcase_27 AC 164 ms
6,940 KB
testcase_28 AC 168 ms
6,944 KB
testcase_29 AC 1,011 ms
6,940 KB
testcase_30 AC 1,070 ms
6,940 KB
testcase_31 AC 940 ms
6,944 KB
testcase_32 AC 862 ms
6,944 KB
testcase_33 AC 369 ms
6,940 KB
testcase_34 AC 360 ms
6,940 KB
testcase_35 AC 366 ms
6,940 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;
}

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

    ll ans = 1;
    vll cnt(3, 0);
    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;
        ll ad = 1;
        
        rep(j, 3)if(j != P[i]) {
            auto it = lower_bound(all(p2ab[j]), mp(B[i], A[i]), les);
            ad *= distance(it, p2ab[j].end()) + 1;
        }
        ans += ad;
        cnt[P[i]]++;

        p2ab[P[i]].push_back(mp(A[i], B[i]));
        sort(all(p2ab[P[i]]));
    }


    rep(i, 3) {
        ll a1, a2, b1, b2;
        each(p, p2ab[i]) {
            tie(a1, b1) = p;
            each(q, p2ab[(i + 1) % 3]) {
                tie(a2, b2) = q;
                if(a1 == b2&&a2 == b1)--ans;
            }
        }
    }

    set<pair<ll, ll>> p3;
    each(p, p2ab[2]) {
        p3.insert(p);
    }

    ll a1, a2, b1, b2, a3, b3, sm1, sm2;
    each(p, p2ab[0]) {
        tie(a1, b1) = p;
        sm1 = a1 + b1;
        each(q, p2ab[1]) {
            tie(a2, b2) = q;
            sm2 = a2 + b2;
            ll L = lcm(sm1, sm2);
            a1 *= L / sm1;
            b1 *= L / sm1;
            a2 *= L / sm2;
            b2 *= L / sm2;
            
            a3 = b1 + b2;
            b3 = a1 + a2 - L;
            if(b3 > 0) {
                ll g = gcd(a3, b3);
                a3 /= g;
                b3 /= g;
                if(p3.count(mp(a3, b3)))--ans;
            }
        }
    }

    cout << ans << endl;
}
0