結果

問題 No.2711 Connecting Lights
ユーザー 👑 kakel-sankakel-san
提出日時 2024-04-09 23:57:25
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 70 ms / 5,000 ms
コード長 2,362 bytes
コンパイル時間 7,777 ms
コンパイル使用メモリ 167,648 KB
実行使用メモリ 186,464 KB
最終ジャッジ日時 2024-04-09 23:57:43
合計ジャッジ時間 10,840 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
29,952 KB
testcase_01 AC 55 ms
30,208 KB
testcase_02 AC 59 ms
30,464 KB
testcase_03 AC 55 ms
30,208 KB
testcase_04 AC 54 ms
30,336 KB
testcase_05 AC 53 ms
29,824 KB
testcase_06 AC 56 ms
30,444 KB
testcase_07 AC 55 ms
30,336 KB
testcase_08 AC 58 ms
29,824 KB
testcase_09 AC 68 ms
30,848 KB
testcase_10 AC 66 ms
30,848 KB
testcase_11 AC 65 ms
30,720 KB
testcase_12 AC 61 ms
30,464 KB
testcase_13 AC 62 ms
30,976 KB
testcase_14 AC 56 ms
30,080 KB
testcase_15 AC 58 ms
30,720 KB
testcase_16 AC 55 ms
30,080 KB
testcase_17 AC 55 ms
30,060 KB
testcase_18 AC 55 ms
30,208 KB
testcase_19 AC 66 ms
30,720 KB
testcase_20 AC 58 ms
30,464 KB
testcase_21 AC 55 ms
29,952 KB
testcase_22 AC 57 ms
30,464 KB
testcase_23 AC 54 ms
30,336 KB
testcase_24 AC 64 ms
30,976 KB
testcase_25 AC 62 ms
30,588 KB
testcase_26 AC 64 ms
30,592 KB
testcase_27 AC 66 ms
30,952 KB
testcase_28 AC 66 ms
30,976 KB
testcase_29 AC 70 ms
186,464 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (97 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 #

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 len = 1 << n;
        var x = new long[len][];
        for (var i = 0; i < len; ++i)
        {
            x[i] = new long[len];
            for (var j = 0; j < len; ++j) if (Popcount(i & j) >= k) x[i][j] = 1;
        }
        var a = new long[1][] { Enumerable.Repeat(1L, len).ToArray() };
        if (m > 1)
        {
            a = Matrix.Mul(a, Matrix.Pow(x, m - 1));
        }
        var ans = 0L;
        for (var i = 0; i < len; ++i) ans = (ans + a[0][i]) % mod;
        WriteLine(ans);
    }
    static int Popcount(int n)
    {
        var ans = 0;
        while (n > 0)
        {
            ans += n % 2;
            n >>= 1;
        }
        return ans;
    }
    static int mod = 998_244_353;
    class Matrix
    {
        // 行列の累乗
        public static long[][] Pow(long[][] m, long k)
        {
            var multi = m;
            var r = new long[m.Length][];
            for (var i = 0; i < m.Length; ++i)
            {
                r[i] = new long[m.Length];
                r[i][i] = 1;
            }
            while (k > 0)
            {
                if ((k & 1) == 1) r = Mul(r, multi);
                multi = Mul(multi, multi);
                k >>= 1;
            }
            return r;
        }
        // 行列の積
        public static long[][] Mul(long[][] x, long[][] y)
        {
            var r = new long[x.Length][];
            for (var i = 0; i < x.Length; ++i) r[i] = new long[y[0].Length];
            for (var i = 0; i < x.Length; ++i) for (var k = 0; k < x[0].Length; ++k)
            {
                for (var j = 0; j < y[0].Length; ++j) r[i][j] = (r[i][j] + x[i][k] * y[k][j]) % mod;
            }
            return r;
        }
    }
}
0