結果

問題 No.461 三角形はいくつ?
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-12-15 13:55:59
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 312 ms / 5,000 ms
コード長 2,038 bytes
コンパイル時間 1,479 ms
コンパイル使用メモリ 150,792 KB
実行使用メモリ 5,036 KB
最終ジャッジ日時 2023-09-02 23:34:41
合計ジャッジ時間 7,991 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 264 ms
4,380 KB
testcase_06 AC 150 ms
4,380 KB
testcase_07 AC 174 ms
4,380 KB
testcase_08 AC 107 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 34 ms
4,376 KB
testcase_11 AC 200 ms
4,380 KB
testcase_12 AC 88 ms
4,380 KB
testcase_13 AC 304 ms
4,380 KB
testcase_14 AC 311 ms
4,376 KB
testcase_15 AC 307 ms
4,380 KB
testcase_16 AC 14 ms
4,380 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 AC 309 ms
4,380 KB
testcase_19 AC 297 ms
4,384 KB
testcase_20 AC 297 ms
5,036 KB
testcase_21 AC 310 ms
4,380 KB
testcase_22 AC 312 ms
4,376 KB
testcase_23 AC 37 ms
4,376 KB
testcase_24 AC 38 ms
4,380 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 5 ms
4,380 KB
testcase_27 AC 190 ms
4,376 KB
testcase_28 AC 5 ms
4,380 KB
testcase_29 AC 69 ms
4,380 KB
testcase_30 AC 33 ms
4,380 KB
testcase_31 AC 126 ms
4,376 KB
testcase_32 AC 157 ms
4,384 KB
testcase_33 AC 5 ms
4,380 KB
testcase_34 AC 5 ms
4,380 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 70 ms
4,376 KB
testcase_37 AC 70 ms
4,380 KB
testcase_38 AC 73 ms
4,376 KB
testcase_39 AC 66 ms
4,376 KB
testcase_40 AC 78 ms
4,376 KB
testcase_41 AC 75 ms
4,376 KB
testcase_42 AC 212 ms
4,380 KB
testcase_43 AC 211 ms
4,380 KB
testcase_44 AC 208 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/dmd2/linux/bin64/../../src/phobos/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!ulong.gcdImpl`

ソースコード

diff #

import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

immutable eps = 1e-18;

long lcm(long a, long b) {
    return a / gcd(a, b) * b;
}
int sign(long x) { return x == 0 ? 0 : cast(int)(x / abs(x)); }
struct Rational {
    long n, d; // numerator, denominator;
    this(long n, long d) {
        if (d < 0) {
            n *= -1;
            d *= -1;
        }
        long g = gcd(abs(n), d);
        this.n = n / g;
        this.d = d / g;
    }
    this(long n) {
        this(n, 1);
    }
    Rational opBinary(string op)(in Rational x) const if (op == "+" || op == "-") {
        long nd = lcm(d, x.d);
        long nn = mixin("n * (nd / d)" ~ op ~ "x.n * (nd / x.d)");
        return Rational(nn, nd);
    }
    Rational opBinary(string op)(real k) const if (op == "*" || op == "/") {
        return Rational(mixin("n" ~ op ~ "k"), d);
    }
    int opCmp(in Rational x) const {
        return (this - x).n.sign;
    }
}

struct P { long a, b; }

void main() {
    auto N = readln.chomp.to!int;
    auto S = new P[][3];
    foreach (i; 0 .. N) {
        int p; long a, b; readf("%s %s %s\n",&p, &a, &b);
        S[p] ~= P(a, b);
    }
    foreach (p; 0 .. 3) S[p] ~= P(1, 0);
    real[] Z;
    foreach (s; S[0]) {
        Z ~= cast(real)(s.a) / (s.a + s.b);
    }
    sort(Z);
    long ans = 0;
    foreach (x; S[1]) {
        foreach (y; S[2]) {
            auto s = cast(real)(x.a) / (x.a + x.b);
            auto t = cast(real)(y.a) / (y.a + y.b);
            if (! (s + t >= 1) ) continue;
            auto lb = 1 - min(s, t);
            auto mid = 2 - (s + t);
            auto sZ = Z.assumeSorted;
            ans += sZ.lowerBound(mid - eps).length - sZ.lowerBound(lb - eps).length;
            ans += sZ.upperBound(mid + eps).length;
        }
    }
    writeln(ans);
}
0