結果

問題 No.2684 折々の色
ユーザー tobisatistobisatis
提出日時 2024-03-20 22:02:09
言語 C#
(.NET 8.0.203)
結果
RE  
実行時間 -
コード長 5,359 bytes
コンパイル時間 8,345 ms
コンパイル使用メモリ 169,440 KB
実行使用メモリ 201,524 KB
最終ジャッジ日時 2024-09-30 07:54:46
合計ジャッジ時間 65,396 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
30,332 KB
testcase_01 AC 57 ms
30,328 KB
testcase_02 AC 53 ms
30,464 KB
testcase_03 AC 52 ms
30,336 KB
testcase_04 RE -
testcase_05 AC 53 ms
30,336 KB
testcase_06 AC 52 ms
30,048 KB
testcase_07 AC 52 ms
30,080 KB
testcase_08 RE -
testcase_09 AC 56 ms
30,048 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 AC 53 ms
30,336 KB
testcase_50 AC 50 ms
30,336 KB
testcase_51 AC 55 ms
30,336 KB
testcase_52 RE -
testcase_53 RE -
testcase_54 AC 55 ms
30,336 KB
testcase_55 AC 55 ms
30,464 KB
testcase_56 AC 52 ms
29,952 KB
testcase_57 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (84 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;

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

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();
}

class HashMap<K, V> : Dictionary<K, V> where K : notnull where V : struct
{
    public new V this[K k]
    {
        get => TryGetValue(k, out var value) ? value : base[k] = default;
        set { base[k] = value; }
    }
}

class AtCoder
{
    object? Solve()
    {
        var n = Int();
        var m = Int();
        var xz = m.Repeat(() => Int() * 100);
        var cz = new Rational<long>[n][];
        for (var i = 0; i < n; i++) cz[i] = new Rational<long>[m];
        var tz = new int[n];
        for (var i = 0; i < n; i++)
        {
            for (var j = 0; j < m; j++) cz[i][j] = Int();
            var t = tz[i] = Int();
            for (var j = 0; j < m; j++) cz[i][j] *= t;
        }

        static long H(Rational<long>[] color)
        {
            var p = 998247893;
            var res = 0L;
            foreach (var x in color)
            {
                res *= 1 << 30;
                res += x.P;
                res %= p;
                res *= 1 << 30;
                res += x.Q;
                res %= p;
            }
            return res;
        }

        var hcz = new long[n];
        for (var i = 0; i < n; i++) hcz[i] = H(cz[i]);
        var hcd = new HashMap<long, int>();
        foreach (var h in hcz) hcd[h]++;

        for (var i = 0; i < n; i++)
        {
            var hi = hcz[i];
            hcd[hi]--;
            var hz = new Rational<long>[m];
            for (var j = 0; j < m; j++) hz[j] = (xz[j] - cz[i][j]) * 100 / (100 - tz[i]);
            var h = H(hz);
            if (hcd[h] > 0) return true;
            hcd[hi]++;
        }
        return false;
    }

    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 };

    #pragma warning disable IDE0051
    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();
    }
    #pragma warning restore IDE0051
}
0