結果
| 問題 | No.461 三角形はいくつ? |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-17 13:49:32 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,344 bytes |
| 記録 | |
| コンパイル時間 | 841 ms |
| コンパイル使用メモリ | 123,904 KB |
| 実行使用メモリ | 8,576 KB |
| 最終ジャッジ日時 | 2024-06-12 05:40:14 |
| 合計ジャッジ時間 | 7,413 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 1 TLE * 1 -- * 39 |
ソースコード
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;
}