結果

問題 No.461 三角形はいくつ?
ユーザー りあんりあん
提出日時 2016-12-08 02:00:48
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,132 bytes
コンパイル時間 1,043 ms
コンパイル使用メモリ 109,824 KB
実行使用メモリ 23,424 KB
最終ジャッジ日時 2024-05-06 18:23:20
合計ジャッジ時間 7,823 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
19,200 KB
testcase_01 AC 26 ms
19,200 KB
testcase_02 AC 26 ms
19,200 KB
testcase_03 AC 23 ms
17,664 KB
testcase_04 TLE -
testcase_05 -- -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;

class Program
{
    static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static Scan sc = new Scan();
    static void Main()
    {
        int n = sc.Int;
        var lines = new List<long[]>[3];
        for (int i = 0; i < 3; i++)
        {
            lines[i] = new List<long[]>();
            lines[i].Add(new long[]{ 0, 1 });
        }
        for (int i = 0; i < n; i++)
        {
            var a = sc.IntArr;
            var g = mymath.gcd(a[1], a[2]);
            lines[a[0]].Add(new long[]{ a[2] / g, (a[1] + a[2]) / g });
        }
        for (int i = 0; i < 3; i++)
            lines[i].Sort((x, y) => (x[0] * y[1]).CompareTo(y[0] * x[1]));

        long ans = 0;
        foreach (var a in lines[0])
        {
            foreach (var b in lines[1])
            {
                if (!okay(a, b)) continue;

                long s = a[0] * b[1] + a[1] * b[0], t = a[1] * b[1];
                var g = mymath.gcd(s, t);
                s /= g;
                t /= g;
                int ok = 0, ng = lines[2].Count;
                while (ok < ng - 1)
                {
                    int m = (ok + ng) >> 1;
                    var c = lines[2][m];
                    if (okay(a, c) && okay(b, c))
                        ok = m;
                    else
                        ng = m;
                }
                ans += ok + 1;
                long u = t - s;
                int l = 0, r = lines[2].Count - 1;
                while (true)
                {
                    int m = (l + r) >> 1;
                    var c = lines[2][m];
                    if (t * c[0] == u * c[1])
                    {
                        --ans;
                        break;
                    }
                    if (l == r) break;

                    if (t * c[0] < u * c[1])
                        l = m + 1;
                    else
                        r = m - 1;
                }
            }
        }
        sw.WriteLine(ans);
        sw.Flush();
    }
    static bool okay(long[] a, long[] b) => a[0] * b[1] + a[1] * b[0] <= a[1] * b[1];
}
class Scan
{
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public string Str => Console.ReadLine().Trim();
    public int[] IntArr => StrArr.Select(int.Parse).ToArray();
    public long[] LongArr => StrArr.Select(long.Parse).ToArray();
    public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
    public string[] StrArr => Str.Split();
}
class mymath
{
    public static long gcd(long a, long b)
    {
        while (b > 0) { var t = a % b; a = b; b = t; }
        return a;
    }
    // a x + b y = gcd(a, b)
    public static long extgcd(long a, long b, out long x, out long y)
    {
        long g = a; x = 1; y = 0;
        if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; }
        return g;
    }
    public static long lcm(long a, long b) => a / gcd(a, b) * b;
}
0