結果

問題 No.2769 Number of Rhombi
ユーザー tobisatistobisatis
提出日時 2024-05-31 21:51:20
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 930 ms / 5,000 ms
コード長 4,715 bytes
コンパイル時間 10,307 ms
コンパイル使用メモリ 170,656 KB
実行使用メモリ 257,820 KB
最終ジャッジ日時 2024-05-31 21:52:01
合計ジャッジ時間 39,814 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
30,976 KB
testcase_01 AC 60 ms
30,312 KB
testcase_02 AC 60 ms
30,720 KB
testcase_03 AC 807 ms
93,288 KB
testcase_04 AC 734 ms
93,424 KB
testcase_05 AC 548 ms
68,776 KB
testcase_06 AC 652 ms
72,032 KB
testcase_07 AC 846 ms
93,056 KB
testcase_08 AC 803 ms
94,876 KB
testcase_09 AC 854 ms
93,076 KB
testcase_10 AC 843 ms
93,224 KB
testcase_11 AC 821 ms
93,112 KB
testcase_12 AC 860 ms
93,072 KB
testcase_13 AC 864 ms
92,844 KB
testcase_14 AC 894 ms
92,980 KB
testcase_15 AC 845 ms
93,488 KB
testcase_16 AC 855 ms
92,976 KB
testcase_17 AC 874 ms
93,088 KB
testcase_18 AC 841 ms
92,848 KB
testcase_19 AC 840 ms
93,108 KB
testcase_20 AC 894 ms
93,092 KB
testcase_21 AC 909 ms
93,236 KB
testcase_22 AC 887 ms
93,236 KB
testcase_23 AC 895 ms
92,984 KB
testcase_24 AC 58 ms
30,592 KB
testcase_25 AC 822 ms
93,100 KB
testcase_26 AC 863 ms
92,840 KB
testcase_27 AC 822 ms
93,232 KB
testcase_28 AC 930 ms
93,352 KB
testcase_29 AC 860 ms
92,972 KB
testcase_30 AC 865 ms
93,228 KB
testcase_31 AC 910 ms
92,964 KB
testcase_32 AC 846 ms
93,232 KB
testcase_33 AC 831 ms
93,232 KB
testcase_34 AC 868 ms
257,820 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (98 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

namespace AtCoder;

#nullable enable

using System.Numerics;

using R = Rational<long>;

readonly record struct Rational<T> :
    IAdditiveIdentity<Rational<T>, Rational<T>>,
    IAdditionOperators<Rational<T>, Rational<T>, Rational<T>>,
    ISubtractionOperators<Rational<T>, Rational<T>, Rational<T>>,
    IUnaryNegationOperators<Rational<T>, Rational<T>>,
    IMultiplicativeIdentity<Rational<T>, Rational<T>>,
    IMultiplyOperators<Rational<T>, Rational<T>, Rational<T>>,
    IDivisionOperators<Rational<T>, Rational<T>, Rational<T>>,
    IComparable<Rational<T>>,
    IEqualityOperators<Rational<T>, Rational<T>, bool>,
    IComparisonOperators<Rational<T>, Rational<T>, bool>
    where T : IBinaryInteger<T>, IConvertible
{
    public T P { get; private init; }
    public T Q { get; private init; }
    public Rational(T p, T q)
    {
        if (q == T.Zero) throw new DivideByZeroException();
        if (q < T.Zero) (p, q) = (-p, -q);
        var (x, y) = (T.Abs(p), q);
        while (y > T.Zero) (x, y) = (y, x % y);
        (P, Q) = (p / x, q / x);
    }
    public Rational(T p) { (P, Q) = (p, T.One); }
    public static Rational<T> AdditiveIdentity => new(T.Zero); 
    public static Rational<T> MultiplicativeIdentity => new(T.One);

    public static implicit operator Rational<T>(T i) => new(i);
    public static Rational<T> operator -(Rational<T> r) => new(-r.P, r.Q);
    public static Rational<T> operator +(Rational<T> r1, Rational<T> r2) => new(r1.P * r2.Q + r1.Q * r2.P, r1.Q * r2.Q);
    public static Rational<T> operator -(Rational<T> r1, Rational<T> r2) => new(r1.P * r2.Q - r1.Q * r2.P, r1.Q * r2.Q);
    public static Rational<T> operator *(Rational<T> r1, Rational<T> r2) => new(r1.P * r2.P, r1.Q * r2.Q);
    public static Rational<T> operator /(Rational<T> r1, Rational<T> r2) => new(r1.P * r2.Q, r1.Q * r2.P);
    public static bool operator <(Rational<T> r1, Rational<T> r2) => r1.CompareTo(r2) < 0;
    public static bool operator <=(Rational<T> r1, Rational<T> r2) => r1.CompareTo(r2) <= 0;
    public static bool operator >(Rational<T> r1, Rational<T> r2) => r1.CompareTo(r2) > 0;
    public static bool operator >=(Rational<T> r1, Rational<T> r2) => r1.CompareTo(r2) >= 0;
    public int CompareTo(Rational<T> r) => (P * r.Q).CompareTo(Q * r.P);
    public override string ToString() => Q == T.One ? P.ToString()! : (P.ToDouble(null) / Q.ToDouble(null)).ToString();
}

static class Extensions
{
    public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray();
}

class AtCoder
{
    object? Solve()
    {
        var n = Int();
        var points = n.Repeat(() => (new R(Int()), new R(Int())));
        var inf = new R(long.MaxValue);
        var d = new Dictionary<(R, R, R), int>();
        for (var i = 0; i < n; i++) for (var j = 0; j < i; j++)
        {
            var (xi, yi) = points[i];
            var (xj, yj) = points[j];
            var xm = (xi + xj) / 2;
            var ym = (yi + yj) / 2;
            var dx = xi - xj;
            var dy = yi - yj;
            var l = inf;
            if (dx != 0) l = dy / dx;
            var key = (xm, ym, l);
            if (d.TryGetValue(key, out var c)) d[key] = c + 1;
            else d[key] = 1;
        }
        var ans = 0L;
        foreach (var ((x, y, l), c) in d)
        {
            var cl = inf;
            if (l == inf) cl = 0;
            else if (l != 0) cl = -1 / l;
            var ck = (x, y, cl);
            if (d.TryGetValue(ck, out var cc)) ans += (long)c * cc;
        }
        return ans / 2;
    }

    public static void Main() => new AtCoder().Run();
    public void Run()
    {
        var res = Solve();
        if (res != null)
        {
            if (res is bool yes) res = yes ? "Yes" : "No";
            sw.WriteLine(res);
        }
        sw.Flush();
    }

    string[] input = Array.Empty<string>();
    int iter = 0;
    readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false };

    string String()
    {
        while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0);
        return input[iter++];
    }
    T Input<T>() where T : IParsable<T> => T.Parse(String(), null);
    int Int() => Input<int>();
    void Out(object? x, string? separator = null)
    {
        separator ??= Environment.NewLine;
        if (x is System.Collections.IEnumerable obj and not string)
        {
            var firstLine = true;
            foreach (var item in obj)
            {
                if (!firstLine) sw.Write(separator);
                firstLine = false;
                sw.Write(item);
            }
        }
        else sw.Write(x);
        sw.WriteLine();
    }
}
0