結果

問題 No.461 三角形はいくつ?
ユーザー mamekinmamekin
提出日時 2017-06-11 22:57:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,570 bytes
コンパイル時間 1,175 ms
コンパイル使用メモリ 112,204 KB
実行使用メモリ 139,600 KB
最終ジャッジ日時 2023-10-24 21:27:38
合計ジャッジ時間 59,555 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 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 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 6 ms
4,372 KB
testcase_26 AC 6 ms
4,372 KB
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

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);
    }
};

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> > seg(3);
    for(int i=0; i<n; ++i){
        int p, a, b;
        cin >> p >> a >> b;
        seg[p].push_back(Fraction(a, a + b));
    }

    vector<Fraction> v;
    v.push_back(0);
    for(const Fraction& a : seg[1]){
        v.push_back(Fraction(1) - a);
        for(const Fraction& b : seg[2]){
            v.push_back(Fraction(1) - b);
            Fraction f = (Fraction(1) - b) / a - a + 1;
            if(f < 1)
                v.push_back(f);
        }
    }
    sort(v.begin(), v.end());

    int ans = 0;
    unsigned k = 0;
    for(const Fraction& f : seg[0]){
        while(k < v.size() && v[k] < f)
            ++ k;
        ans += k;
    }
    ans += v.size();
    cout << ans << endl;

    return 0;
}
0