結果

問題 No.3486 Draw a Rainbow
コンテスト
ユーザー detteiuu
提出日時 2026-03-27 22:48:47
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 2,256 ms / 4,000 ms
コード長 811 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,043 ms
コンパイル使用メモリ 84,864 KB
実行使用メモリ 176,640 KB
最終ジャッジ日時 2026-03-30 14:24:02
合計ジャッジ時間 23,664 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from sys import stdin
input = stdin.readline

N, M, L = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

MOD = 998244353

cnt = [[0]*L for _ in range(M)]
for A, B in AB:
    A, B = A-1, B-1-M
    cnt[A][B] += 1
for i in range(M):
    for j in range(L):
        cnt[i][j] = (pow(2, cnt[i][j])-1)%MOD

dp = [0]*(1<<L)
dp[0] = 1
for i in range(M):
    ndp = dp[:]
    for j in range(L):
        for bit in range(1<<L):
            if 1<<j & bit:
                ndp[bit] += ndp[bit]*cnt[i][j]%MOD
                ndp[bit] %= MOD
    for j in range(L):
        for bit in range(1<<L):
            if not 1<<j & bit:
                ndp[bit|1<<j] += ndp[bit]*cnt[i][j]%MOD
                ndp[bit|1<<j] %= MOD
    dp = [(ndp[bit]-dp[bit])%MOD for bit in range(1<<L)]

print(dp[-1])
0