結果

問題 No.2561 みんな大好きmod 998
ユーザー bluemeganebluemegane
提出日時 2023-12-02 18:37:37
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 1,696 ms / 4,000 ms
コード長 1,994 bytes
コンパイル時間 8,913 ms
コンパイル使用メモリ 158,100 KB
実行使用メモリ 203,308 KB
最終ジャッジ日時 2023-12-02 18:38:12
合計ジャッジ時間 32,552 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
32,420 KB
testcase_01 AC 160 ms
56,100 KB
testcase_02 AC 68 ms
32,420 KB
testcase_03 AC 1,681 ms
56,100 KB
testcase_04 AC 1,682 ms
56,100 KB
testcase_05 AC 1,677 ms
56,100 KB
testcase_06 AC 1,696 ms
56,100 KB
testcase_07 AC 73 ms
32,548 KB
testcase_08 AC 71 ms
32,420 KB
testcase_09 AC 74 ms
34,084 KB
testcase_10 AC 70 ms
32,420 KB
testcase_11 AC 308 ms
56,100 KB
testcase_12 AC 69 ms
32,420 KB
testcase_13 AC 80 ms
32,548 KB
testcase_14 AC 70 ms
32,548 KB
testcase_15 AC 1,662 ms
56,100 KB
testcase_16 AC 71 ms
32,548 KB
testcase_17 AC 71 ms
32,420 KB
testcase_18 AC 70 ms
32,676 KB
testcase_19 AC 1,217 ms
56,100 KB
testcase_20 AC 72 ms
32,932 KB
testcase_21 AC 70 ms
32,420 KB
testcase_22 AC 70 ms
32,420 KB
testcase_23 AC 68 ms
32,676 KB
testcase_24 AC 72 ms
32,420 KB
testcase_25 AC 78 ms
32,420 KB
testcase_26 AC 406 ms
56,100 KB
testcase_27 AC 1,687 ms
56,100 KB
testcase_28 AC 536 ms
56,100 KB
testcase_29 AC 210 ms
56,100 KB
testcase_30 AC 461 ms
56,100 KB
testcase_31 AC 901 ms
56,100 KB
testcase_32 AC 263 ms
56,100 KB
testcase_33 AC 204 ms
56,100 KB
testcase_34 AC 1,694 ms
56,100 KB
testcase_35 AC 196 ms
56,100 KB
testcase_36 AC 191 ms
56,100 KB
testcase_37 AC 130 ms
56,100 KB
testcase_38 AC 329 ms
56,100 KB
testcase_39 AC 439 ms
56,100 KB
testcase_40 AC 439 ms
56,100 KB
testcase_41 AC 333 ms
56,100 KB
testcase_42 AC 503 ms
56,100 KB
testcase_43 AC 129 ms
56,100 KB
testcase_44 AC 249 ms
56,100 KB
testcase_45 AC 1,198 ms
56,100 KB
testcase_46 AC 224 ms
203,308 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (95 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  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;

class Perm
{
    public static void Swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }

    public static bool NextPermutation<T>(T[] array, int index, int length, Comparison<T> comp)
    {
        if (length <= 1) return false;
        for (int i = length - 1; i > 0; i--)
        {
            int k = i - 1;
            if (comp(array[k], array[i]) < 0)
            {
                int j = Array.FindLastIndex(array, delegate (T x) { return comp(array[k], x) < 0; });
                Swap(ref array[k], ref array[j]);
                Array.Reverse(array, i, length - i);
                return true;
            }
        }
        Array.Reverse(array, index, length);
        return false;
    }

    public static bool NextPermutation<T>(T[] array) where T : IComparable
    {
        return NextPermutation(array, 0, array.Length, Comparer<T>.Default.Compare);
    }
}


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 n, int[] a, int[] b)
    {
        var s998 = 0L;
        var sMOD = 0L;
        for (int i = 0; i < n; i++)
        {
            if (b[i] == 0)
            {
                s998 += a[i];
                sMOD += a[i];
                s998 %= 998;
                sMOD %= MOD;
            }
        }
        return sMOD <= s998;
    }
    static void getAns(int n, int k, int[] a)
    {
        var c = 0L;
        var b = Enumerable.Repeat(1, n).ToArray();
        for (int i = 0; i < k; i++) b[i] = 0;
        do
        {
            if (calc(n,a, b)) c++;
        }
        while (Perm.NextPermutation(b));
        Console.WriteLine(c %= 998);
    }
}
0