結果
問題 | No.1492 01文字列と転倒 |
ユーザー |
![]() |
提出日時 | 2025-03-20 20:23:26 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,255 bytes |
コンパイル時間 | 357 ms |
コンパイル使用メモリ | 82,416 KB |
実行使用メモリ | 282,628 KB |
最終ジャッジ日時 | 2025-03-20 20:25:49 |
合計ジャッジ時間 | 6,226 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | TLE * 1 -- * 21 |
ソースコード
from collections import defaultdictdef main():import sysinput = sys.stdin.read().split()N = int(input[0])M = int(input[1])current = defaultdict(lambda: defaultdict(int))current[0][0] = 1 # Initial state: length 0, balance 0, inversion count 0for step in range(2 * N):next_step = defaultdict(lambda: defaultdict(int))for o in current:ks = current[o]for k in ks:cnt = ks[k]# Option 1: Add '0'new_o = o + 1delta = (step - o) // 2new_k = k + deltanext_step[new_o][new_k] = (next_step[new_o][new_k] + cnt) % M# Option 2: Add '1' if possibleif o > 0:new_o2 = o - 1new_k2 = knext_step[new_o2][new_k2] = (next_step[new_o2][new_k2] + cnt) % Mcurrent = next_step# Collect results for balance 0max_k = N * Nresult = [0] * (max_k + 1)if 0 in current:for k in current[0]:if k <= max_k:result[k] = current[0][k] % Mfor val in result:print(val % M)if __name__ == '__main__':main()