結果

問題 No.1304 あなたは基本が何か知っていますか?私は知っています.
コンテスト
ユーザー lam6er
提出日時 2025-03-31 17:32:07
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,504 ms / 2,000 ms
+ 548µs
コード長 1,294 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 223 ms
コンパイル使用メモリ 96,364 KB
実行使用メモリ 159,656 KB
最終ジャッジ日時 2026-07-12 18:32:44
合計ジャッジ時間 22,008 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 52 TLE * 2 MLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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