結果

問題 No.461 三角形はいくつ?
ユーザー nebukuro09nebukuro09
提出日時 2016-12-17 13:49:32
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 2,344 bytes
コンパイル時間 928 ms
コンパイル使用メモリ 114,492 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 23:37:21
合計ジャッジ時間 8,645 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 75 ms
4,376 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
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 #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;


class Fraction {
    long n, m;
    
    this(long n, long m) {
        if (m < 0) {
            n *= -1;
            m *= -1;
        }
        
        long g = gcd(n, m);
        this.n = n / g;
        this.m = m / g;
    }

    long gcd(long a, long b) {
        a = abs(a);
        b = abs(b);
        long c;
        while (b) {
            c = a % b;
            a = b;
            b = c;
        }
        return a;
    }

    Fraction opBinary(string op)(Fraction f) {
        long a = this.n;
        long b = this.m;
        long x = op == "-" ? -f.n : f.n;
        long y = f.m;
        static if (op == "+" || op == "-") {
            long g = gcd(b, y);
            auto ret = new Fraction(y/g*a + b/g*x , b*y/g);
            return ret;
        }
        else static assert(0, "Operator "~op~" not implemented");
    }

    override bool opEquals(Object o) {
        auto f = cast(Fraction) o;
        if (f is null) return false;
        return n == f.n && m == f.m;
    }

    override int opCmp(Object o) {
        auto f = cast(Fraction) o;
        auto ret = (this - f).n;
        if (ret > 0)
            return 1;
        else if (ret == 0)
            return 0;
        else
            return -1;
    }

    override string toString() {
        return n.to!string ~ "/" ~ m.to!string;
    }

}

void main() {
    auto N = readln.chomp.to!int;
    auto V = new Fraction[][](3);
    auto ONE = new Fraction(1, 1);
    
    foreach (i; 0..N) {
        auto s = readln.split.map!(to!long);
        int p = s[0].to!int;
        V[p] ~= new Fraction(s[2], s[1] + s[2]);
    }

    long ans = N + 1;
    
    foreach (i; 0..3)
        foreach (v1; V[i])
            foreach (v2; V[(i+1)%3])
                if (v1 + v2 < ONE)
                    ans++;

    auto W = V[2].sort().assumeSorted;
    int Wn = W.length.to!int;
    foreach (v1; V[0]) {
        foreach (v2; V[1]) {
            if (v1 + v2 > ONE)
                continue;
            ans += Wn - W.upperBound(ONE-max(v1, v2)).length.to!int;
            ans -= Wn - W.lowerBound(ONE-v1-v2).length - W.upperBound(ONE-v1-v2).length;
        }
    }

    ans.writeln;
}
0