結果

問題 No.2561 みんな大好きmod 998
ユーザー bluemeganebluemegane
提出日時 2023-12-02 18:33:59
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 1,907 bytes
コンパイル時間 16,126 ms
コンパイル使用メモリ 158,536 KB
実行使用メモリ 203,644 KB
最終ジャッジ日時 2023-12-02 18:34:56
合計ジャッジ時間 49,189 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 203 ms
56,356 KB
testcase_02 AC 83 ms
32,676 KB
testcase_03 AC 2,877 ms
56,612 KB
testcase_04 AC 2,909 ms
56,612 KB
testcase_05 AC 2,889 ms
56,612 KB
testcase_06 WA -
testcase_07 AC 83 ms
32,804 KB
testcase_08 AC 81 ms
32,676 KB
testcase_09 AC 88 ms
34,340 KB
testcase_10 AC 82 ms
32,676 KB
testcase_11 AC 565 ms
56,356 KB
testcase_12 AC 83 ms
32,676 KB
testcase_13 AC 84 ms
32,804 KB
testcase_14 AC 82 ms
32,804 KB
testcase_15 WA -
testcase_16 AC 83 ms
32,804 KB
testcase_17 AC 83 ms
32,676 KB
testcase_18 AC 84 ms
32,932 KB
testcase_19 WA -
testcase_20 AC 86 ms
33,188 KB
testcase_21 AC 83 ms
32,676 KB
testcase_22 AC 83 ms
32,676 KB
testcase_23 AC 84 ms
32,932 KB
testcase_24 AC 84 ms
32,676 KB
testcase_25 AC 83 ms
32,676 KB
testcase_26 AC 775 ms
56,356 KB
testcase_27 AC 2,873 ms
56,612 KB
testcase_28 AC 1,043 ms
56,356 KB
testcase_29 AC 316 ms
56,356 KB
testcase_30 AC 778 ms
56,356 KB
testcase_31 AC 1,682 ms
56,356 KB
testcase_32 AC 504 ms
56,356 KB
testcase_33 AC 345 ms
56,356 KB
testcase_34 AC 2,860 ms
56,612 KB
testcase_35 AC 330 ms
56,356 KB
testcase_36 AC 329 ms
56,356 KB
testcase_37 AC 192 ms
56,356 KB
testcase_38 AC 560 ms
56,356 KB
testcase_39 AC 779 ms
56,356 KB
testcase_40 AC 807 ms
56,356 KB
testcase_41 AC 562 ms
56,356 KB
testcase_42 AC 1,007 ms
56,356 KB
testcase_43 AC 202 ms
56,356 KB
testcase_44 AC 425 ms
56,356 KB
testcase_45 AC 2,255 ms
56,612 KB
testcase_46 AC 404 ms
203,644 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (109 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[] 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;
        var b = Enumerable.Repeat(1, n).ToArray();
        for (int i = 0; i < k; i++) b[i] = 0;
        do
        {
            if (calc(a, b)) c++;
        }
        while (Perm.NextPermutation(b));
        Console.WriteLine(c %= 998);
    }
}
0