結果

問題 No.2711 Connecting Lights
ユーザー rlangevinrlangevin
提出日時 2024-04-01 22:03:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 1,413 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 64,312 KB
最終ジャッジ日時 2024-04-01 22:03:36
合計ジャッジ時間 2,697 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 44 ms
59,976 KB
testcase_02 AC 49 ms
62,100 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 AC 36 ms
53,460 KB
testcase_05 AC 44 ms
59,968 KB
testcase_06 AC 49 ms
62,248 KB
testcase_07 AC 43 ms
59,968 KB
testcase_08 AC 45 ms
62,248 KB
testcase_09 AC 61 ms
64,156 KB
testcase_10 AC 60 ms
64,156 KB
testcase_11 AC 57 ms
64,156 KB
testcase_12 AC 47 ms
64,312 KB
testcase_13 AC 47 ms
64,312 KB
testcase_14 AC 44 ms
62,248 KB
testcase_15 AC 48 ms
64,312 KB
testcase_16 AC 41 ms
59,968 KB
testcase_17 AC 42 ms
59,968 KB
testcase_18 AC 47 ms
62,248 KB
testcase_19 AC 59 ms
64,156 KB
testcase_20 AC 48 ms
64,312 KB
testcase_21 AC 42 ms
59,968 KB
testcase_22 AC 45 ms
59,968 KB
testcase_23 AC 37 ms
53,460 KB
testcase_24 AC 58 ms
64,156 KB
testcase_25 AC 61 ms
64,156 KB
testcase_26 AC 62 ms
64,156 KB
testcase_27 AC 62 ms
64,156 KB
testcase_28 AC 62 ms
64,156 KB
testcase_29 AC 61 ms
64,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Matprod(A, B, mod, N):
    temp = [0] * N*N
    for i in range(N):
        for j in range(N):
            ij = i * N + j
            for k in range(N):
                temp[ij] += A[i*N+k] * B[k*N+j]
                temp[ij] %= mod
    return temp

def Matpow_Linear(A, M, mod, N):
    Mat = [0] * N*N
    for i in range(N):
        Mat[i*N+i] = 1
    while M:
        if M & 1:
            Mat = Matprod(Mat, A, mod, N)
        A = Matprod(A, A, mod, N)
        M >>= 1
    return Mat

# https://qiita.com/zawawahoge/items/8bbd4c2319e7f7746266
def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f





N, M, K = map(int, input().split())
mod = 998244353
N2 = 1 << N
Mat = [0] * (N2 * N2)
for i in range(N2):
    for j in range(N2):
        if popcount(i & j) >= K:
            Mat[i*N2 + j] = 1
            
Mat = Matpow_Linear(Mat, M - 1, mod, N2)    
print(sum(Mat)%mod)
0