結果

問題 No.1710 Minimum OR is X
ユーザー 👑 kakel-sankakel-san
提出日時 2024-01-25 00:23:43
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 253 ms / 2,000 ms
コード長 2,770 bytes
コンパイル時間 14,724 ms
コンパイル使用メモリ 158,464 KB
実行使用メモリ 179,696 KB
最終ジャッジ日時 2024-01-25 00:24:05
合計ジャッジ時間 12,370 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
32,420 KB
testcase_01 AC 75 ms
32,420 KB
testcase_02 AC 102 ms
32,676 KB
testcase_03 AC 75 ms
32,420 KB
testcase_04 AC 75 ms
32,420 KB
testcase_05 AC 76 ms
32,420 KB
testcase_06 AC 76 ms
32,420 KB
testcase_07 AC 76 ms
32,420 KB
testcase_08 AC 130 ms
32,804 KB
testcase_09 AC 124 ms
32,804 KB
testcase_10 AC 158 ms
32,804 KB
testcase_11 AC 129 ms
32,804 KB
testcase_12 AC 144 ms
32,804 KB
testcase_13 AC 135 ms
32,804 KB
testcase_14 AC 140 ms
32,804 KB
testcase_15 AC 99 ms
32,804 KB
testcase_16 AC 140 ms
32,804 KB
testcase_17 AC 99 ms
32,676 KB
testcase_18 AC 246 ms
32,932 KB
testcase_19 AC 197 ms
32,804 KB
testcase_20 AC 120 ms
32,804 KB
testcase_21 AC 236 ms
32,932 KB
testcase_22 AC 253 ms
32,932 KB
testcase_23 AC 77 ms
32,420 KB
testcase_24 AC 80 ms
32,548 KB
testcase_25 AC 79 ms
32,804 KB
testcase_26 AC 76 ms
32,548 KB
testcase_27 AC 86 ms
32,932 KB
testcase_28 AC 90 ms
32,932 KB
testcase_29 AC 77 ms
32,548 KB
testcase_30 AC 77 ms
32,548 KB
testcase_31 AC 83 ms
32,932 KB
testcase_32 AC 92 ms
179,696 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (133 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;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
    static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m, k) = (c[0], c[1], c[2]);
        var x = ReadLine();
        var mod = 998_244_353;
        WriteLine(CountX(n, m, k, x, mod));
    }
    static long CountX(int n, int m, int k, string x, int mod)
    {
        var dp = new long[m + 1, n - k + 1];
        dp[0, 0] = 1;
        var ncr = new NCR(n + 1, mod);
        for (var i = 0; i < m; ++i) for (var j = 0; j <= n - k; ++j)
        {
            var exp = ncr.Exp(2, j);
            if (x[i] == '0')
            {
                for (var one = 0; j + one <= n - k; ++one) dp[i + 1, j + one] = (dp[i + 1, j + one]
                    + dp[i, j] * ncr.Calc(n - j, one) % mod * exp % mod) % mod;
            }
            else
            {
                for (var zero = 0; zero <= n - j && zero < k; ++zero) dp[i + 1, j] = (dp[i + 1, j]
                    + dp[i, j] * ncr.Calc(n - j, zero) % mod * exp % mod) % mod;
            }
        }
        var ans = 0L;
        for (var i = 0; i <= n - k; ++i) ans = (ans + dp[m, i]) % mod;
        return ans;
    }
    class NCR
    {
        int[] facts;
        int[] revFacts;
        int mod;
        public NCR(int n, int mod)
        {
            facts = new int[n + 1];
            revFacts = new int[n + 1];
            this.mod = mod;
            facts[0] = 1;
            var tmp = 1L;
            for (var i = 1; i <= n; ++i)
            {
                tmp = tmp * i % mod;
                facts[i] = (int)tmp;
            }
            tmp = Exp(facts[n], mod - 2);
            revFacts[n] = (int)tmp;
            for (var i = n; i > 1; --i)
            {
                tmp = tmp * i % mod;
                revFacts[i - 1] = (int)tmp;
            }
            revFacts[0] = 1;
        }
        public long Exp(long n, long k)
        {
            n = n % mod;
            if (k == 0) return 1;
            if (k == 1) return n;
            var half = Exp(n, k / 2);
            var result = half * half % mod;
            return ((k % 2) == 0) ? result : (result * n % mod);
        }
        public long Calc(int n, int r)
        {
            return (long)facts[n] * revFacts[r] % mod * revFacts[n - r] % mod;
        }
    }
}
0