結果

問題 No.1304 あなたは基本が何か知っていますか?私は知っています.
ユーザー lam6er
提出日時 2025-03-31 17:32:07
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,294 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 82,200 KB
実行使用メモリ 167,084 KB
最終ジャッジ日時 2025-06-22 03:09:40
合計ジャッジ時間 13,145 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 48 TLE * 2 -- * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict

MOD = 998244353

def main():
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx]); idx +=1
    K = int(input[idx]); idx +=1
    X = int(input[idx]); idx +=1
    Y = int(input[idx]); idx +=1
    A = list(map(int, input[idx:idx+K]))
    
    # Initial state: after first element
    # state is a dict where key is prev element, value is a dict of {xor_val: count}
    current = defaultdict(dict)
    for a in A:
        if a not in current:
            current[a] = defaultdict(int)
        current[a][a] = 1
    
    for _ in range(N - 1):
        next_state = defaultdict(lambda: defaultdict(int))
        for prev_val in current:
            for xor_val in current[prev_val]:
                cnt = current[prev_val][xor_val]
                for a in A:
                    if a == prev_val:
                        continue
                    new_xor = xor_val ^ a
                    next_state[a][new_xor] = (next_state[a][new_xor] + cnt) % MOD
        current = next_state
    
    total = 0
    for a in current:
        xor_dict = current[a]
        for x in range(X, Y + 1):
            if x in xor_dict:
                total = (total + xor_dict[x]) % MOD
    print(total % MOD)

if __name__ == "__main__":
    main()
0