結果

問題 No.2684 折々の色
ユーザー tobisatistobisatis
提出日時 2024-03-20 22:24:35
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 1,616 ms / 2,000 ms
コード長 5,485 bytes
コンパイル時間 11,471 ms
コンパイル使用メモリ 166,824 KB
実行使用メモリ 194,984 KB
最終ジャッジ日時 2024-09-30 08:24:06
合計ジャッジ時間 49,654 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
30,720 KB
testcase_01 AC 58 ms
30,592 KB
testcase_02 AC 59 ms
30,444 KB
testcase_03 AC 59 ms
30,720 KB
testcase_04 AC 80 ms
30,692 KB
testcase_05 AC 61 ms
30,464 KB
testcase_06 AC 60 ms
30,444 KB
testcase_07 AC 59 ms
30,720 KB
testcase_08 AC 62 ms
30,720 KB
testcase_09 AC 58 ms
30,720 KB
testcase_10 AC 62 ms
30,372 KB
testcase_11 AC 737 ms
96,132 KB
testcase_12 AC 429 ms
81,596 KB
testcase_13 AC 490 ms
97,100 KB
testcase_14 AC 285 ms
73,312 KB
testcase_15 AC 471 ms
82,116 KB
testcase_16 AC 135 ms
45,952 KB
testcase_17 AC 376 ms
72,708 KB
testcase_18 AC 474 ms
91,000 KB
testcase_19 AC 603 ms
99,456 KB
testcase_20 AC 420 ms
81,604 KB
testcase_21 AC 199 ms
54,784 KB
testcase_22 AC 721 ms
102,360 KB
testcase_23 AC 687 ms
88,192 KB
testcase_24 AC 288 ms
66,560 KB
testcase_25 AC 461 ms
75,908 KB
testcase_26 AC 871 ms
98,912 KB
testcase_27 AC 548 ms
83,848 KB
testcase_28 AC 676 ms
88,188 KB
testcase_29 AC 1,199 ms
118,984 KB
testcase_30 AC 1,061 ms
118,712 KB
testcase_31 AC 737 ms
116,788 KB
testcase_32 AC 1,512 ms
130,968 KB
testcase_33 AC 989 ms
122,068 KB
testcase_34 AC 1,227 ms
127,272 KB
testcase_35 AC 1,232 ms
127,252 KB
testcase_36 AC 762 ms
116,708 KB
testcase_37 AC 920 ms
117,640 KB
testcase_38 AC 1,589 ms
132,172 KB
testcase_39 AC 1,587 ms
132,296 KB
testcase_40 AC 1,593 ms
132,292 KB
testcase_41 AC 1,607 ms
132,044 KB
testcase_42 AC 1,598 ms
132,164 KB
testcase_43 AC 1,613 ms
132,292 KB
testcase_44 AC 1,616 ms
132,160 KB
testcase_45 AC 1,598 ms
132,164 KB
testcase_46 AC 1,605 ms
132,160 KB
testcase_47 AC 59 ms
30,720 KB
testcase_48 AC 61 ms
30,720 KB
testcase_49 AC 61 ms
30,336 KB
testcase_50 AC 60 ms
30,720 KB
testcase_51 AC 60 ms
30,848 KB
testcase_52 AC 59 ms
30,572 KB
testcase_53 AC 60 ms
30,464 KB
testcase_54 AC 60 ms
30,528 KB
testcase_55 AC 60 ms
30,720 KB
testcase_56 AC 60 ms
30,592 KB
testcase_57 AC 60 ms
194,984 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (114 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(() => new Rational<long>(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 ulong H(Rational<long>[] color)
        {
            var p = 998247893U;
            var res = 0UL;
            foreach (var x in color)
            {
                res *= p;
                res += (ulong)x.P;
                res *= p;
                res += (ulong)x.Q;
            }
            return res;
        }

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

        for (var i = 0; i < n; i++)
        {
            var hi = hcz[i];
            if (tz[i] == 100)
            {
                if (hx == hi) return true;
                continue;
            }
            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