結果

問題 No.461 三角形はいくつ?
ユーザー mamekinmamekin
提出日時 2017-07-09 17:42:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4,267 ms / 5,000 ms
コード長 3,912 bytes
コンパイル時間 1,345 ms
コンパイル使用メモリ 112,028 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 11:07:47
合計ジャッジ時間 36,354 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 1,232 ms
5,376 KB
testcase_06 AC 729 ms
5,376 KB
testcase_07 AC 840 ms
5,376 KB
testcase_08 AC 575 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 179 ms
5,376 KB
testcase_11 AC 996 ms
5,376 KB
testcase_12 AC 437 ms
5,376 KB
testcase_13 AC 1,462 ms
5,376 KB
testcase_14 AC 1,490 ms
5,376 KB
testcase_15 AC 1,452 ms
5,376 KB
testcase_16 AC 623 ms
5,376 KB
testcase_17 AC 622 ms
5,376 KB
testcase_18 AC 2,005 ms
5,376 KB
testcase_19 AC 1,933 ms
5,376 KB
testcase_20 AC 1,417 ms
5,376 KB
testcase_21 AC 1,492 ms
5,376 KB
testcase_22 AC 1,488 ms
5,376 KB
testcase_23 AC 521 ms
5,376 KB
testcase_24 AC 510 ms
5,376 KB
testcase_25 AC 7 ms
5,376 KB
testcase_26 AC 7 ms
5,376 KB
testcase_27 AC 4,267 ms
5,376 KB
testcase_28 AC 7 ms
5,376 KB
testcase_29 AC 413 ms
5,376 KB
testcase_30 AC 194 ms
5,376 KB
testcase_31 AC 799 ms
5,376 KB
testcase_32 AC 1,037 ms
5,376 KB
testcase_33 AC 6 ms
5,376 KB
testcase_34 AC 9 ms
5,376 KB
testcase_35 AC 8 ms
5,376 KB
testcase_36 AC 600 ms
5,376 KB
testcase_37 AC 631 ms
5,376 KB
testcase_38 AC 635 ms
5,376 KB
testcase_39 AC 655 ms
5,376 KB
testcase_40 AC 646 ms
5,376 KB
testcase_41 AC 623 ms
5,376 KB
testcase_42 AC 999 ms
5,376 KB
testcase_43 AC 984 ms
5,376 KB
testcase_44 AC 1,024 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

template <class T1>
class Operators
{
public:
    template <class T2>
    const T1 operator+(const T2& right) const{
        T1 ans = static_cast<const T1&>( *this );
        ans += right;
        return ans;
    }
    template <class T2>
    const T1 operator-(const T2& right) const{
        T1 ans = static_cast<const T1&>( *this );
        ans -= right;
        return ans;
    }
    template <class T2>
    const T1 operator*(const T2& right) const{
        T1 ans = static_cast<const T1&>( *this );
        ans *= right;
        return ans;
    }
    template <class T2>
    const T1 operator/(const T2& right) const{
        T1 ans = static_cast<const T1&>( *this );
        ans /= right;
        return ans;
    }
    bool operator!=(const T1& right) const{
        const T1& left = static_cast<const T1&>( *this );
        return !(left == right);
    }
    bool operator>(const T1& right) const{
        const T1& left = static_cast<const T1&>( *this );
        return right < left;
    }
    bool operator<=(const T1& right) const{
        const T1& left = static_cast<const T1&>( *this );
        return !(right < left);
    }
    bool operator>=(const T1& right) const{
        const T1& left = static_cast<const T1&>( *this );
        return !(left < right);
    }
};

class Fraction : public Operators<Fraction>
{
private:
    long long n; // 分子(numerator)
    long long d; // 分母(denominator)

    // 約分
    void reduce(){
        if(d < 0){
            n *= -1;
            d *= -1;
        }
        long long a = abs(n);
        long long b = d;
        while(b != 0){
            long long tmp = a % b;
            a = b;
            b = tmp;
        }
        n /= a;
        d /= a;
    }
public:
    Fraction(){
        n = 0;
        d = 1;
    }
    Fraction(long long n0){
        n = n0;
        d = 1;
    }
    Fraction(long long n0, long long d0){
        n = n0;
        d = d0;
        reduce();
    }
    pair<long long, long long> getValue() const{
        return make_pair(n, d);
    }
    Fraction& operator+=(const Fraction& f){
        n = n * f.d + d * f.n;
        d *= f.d;
        reduce();
        return *this;
    }
    Fraction& operator-=(const Fraction& f){
        n = n * f.d - d * f.n;
        d *= f.d;
        reduce();
        return *this;
    }
    Fraction& operator*=(const Fraction& f){
        n *= f.n;
        d *= f.d;
        reduce();
        return *this;
    }
    Fraction& operator/=(const Fraction& f){
        n *= f.d;
        d *= f.n;
        reduce();
        return *this;
    }
    bool operator==(const Fraction& f) const{
        return n == f.n && d == f.d;
    }
    bool operator<(const Fraction& f) const{
        return n * f.d < f.n * d;
    }
};

int main()
{
    int n;
    cin >> n;
    vector<vector<Fraction> > v(3, vector<Fraction>(1, 1));
    for(int i=0; i<n; ++i){
        int p, a, b;
        cin >> p >> a >> b;
        v[p].push_back(Fraction(a, a + b));
    }

    long long ans = 0;
    sort(v[0].begin(), v[0].end());
    for(Fraction a : v[1]){
        for(Fraction b : v[2]){
            if(a + b < 1)
                continue;

            Fraction c = Fraction(1) - min(a, b);
            ans += v[0].end() - lower_bound(v[0].begin(), v[0].end(), c);

            Fraction d = Fraction(2) - a - b;
            if(binary_search(v[0].begin(), v[0].end(), d))
                -- ans;
        }
    }
    cout << ans << endl;

    return 0;
}
0