結果

問題 No.2561 みんな大好きmod 998
ユーザー bluemeganebluemegane
提出日時 2023-12-02 17:09:53
言語 C#
(.NET 8.0.203)
結果
TLE  
実行時間 -
コード長 1,642 bytes
コンパイル時間 7,797 ms
コンパイル使用メモリ 158,380 KB
実行使用メモリ 203,212 KB
最終ジャッジ日時 2023-12-02 17:11:01
合計ジャッジ時間 60,513 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
32,420 KB
testcase_01 AC 285 ms
55,972 KB
testcase_02 AC 70 ms
32,420 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 AC 71 ms
32,548 KB
testcase_08 AC 70 ms
32,420 KB
testcase_09 AC 77 ms
36,260 KB
testcase_10 AC 68 ms
32,420 KB
testcase_11 AC 753 ms
56,100 KB
testcase_12 AC 82 ms
32,420 KB
testcase_13 AC 68 ms
32,548 KB
testcase_14 AC 68 ms
32,548 KB
testcase_15 TLE -
testcase_16 AC 70 ms
32,548 KB
testcase_17 AC 73 ms
32,420 KB
testcase_18 AC 75 ms
32,804 KB
testcase_19 AC 3,144 ms
56,484 KB
testcase_20 AC 74 ms
32,932 KB
testcase_21 AC 69 ms
32,420 KB
testcase_22 AC 69 ms
32,420 KB
testcase_23 AC 73 ms
32,676 KB
testcase_24 AC 71 ms
32,420 KB
testcase_25 AC 67 ms
32,420 KB
testcase_26 AC 1,024 ms
56,100 KB
testcase_27 TLE -
testcase_28 AC 1,326 ms
56,100 KB
testcase_29 AC 458 ms
55,972 KB
testcase_30 AC 1,248 ms
56,100 KB
testcase_31 AC 2,431 ms
56,356 KB
testcase_32 AC 532 ms
55,972 KB
testcase_33 AC 450 ms
55,972 KB
testcase_34 TLE -
testcase_35 AC 366 ms
55,972 KB
testcase_36 AC 352 ms
55,972 KB
testcase_37 AC 231 ms
55,972 KB
testcase_38 AC 758 ms
56,100 KB
testcase_39 AC 1,251 ms
56,100 KB
testcase_40 AC 1,268 ms
56,100 KB
testcase_41 AC 774 ms
56,100 KB
testcase_42 AC 1,363 ms
56,100 KB
testcase_43 AC 205 ms
55,972 KB
testcase_44 AC 601 ms
55,972 KB
testcase_45 AC 3,134 ms
56,484 KB
testcase_46 AC 478 ms
203,212 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (113 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
/home/judge/data/code/Main.cs(5,21): warning CS8981: 型名 'combi' には、小文字の ASCII 文字のみが含まれています。このような名前は、プログラミング言語用に予約されている可能性があります。 [/home/judge/data/code/main.csproj]
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System.Collections.Generic;
using System.Linq;
using System;

public static class combi
{
    public static IEnumerable<IEnumerable<T>> Comb<T>(this IEnumerable<T> items, int r)
    {
        if (r == 0)
        {
            yield return Enumerable.Empty<T>();
        }
        else
        {
            var i = 1;
            foreach (var x in items)
            {
                var xs = items.Skip(i);
                foreach (var c in Comb(xs, r - 1))
                    yield return c.Before(x);
                i++;
            }
        }
    }
    public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
    {
        yield return first;
        foreach (var i in items)
            yield return i;
    }
}

public class Hello
{
    public static int MOD = 998244353;
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(n, k, a);
    }
    static bool calc(int[] a, int[] p)
    {
        var s998 = 0L;
        var sMOD = 0L;
        foreach (var x in p)
        {
            s998 += a[x];
            s998 %= 998;
            sMOD += a[x];
            sMOD %= MOD;
        }
        return sMOD <= s998;
    }
    static void getAns(int n, int k, int[] a)
    {
        var c = 0L;
        foreach (var x in Enumerable.Range(0, n).Comb(k))
        {
            var p = x.ToArray();
            if (calc(a, p)) c++;
        }
        Console.WriteLine(c %= 998);
    }
}
0