結果
| 問題 |
No.2807 Have Another Go (Easy)
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 18:28:35 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,629 bytes |
| コンパイル時間 | 187 ms |
| コンパイル使用メモリ | 81,912 KB |
| 実行使用メモリ | 59,008 KB |
| 最終ジャッジ日時 | 2025-06-12 18:28:41 |
| 合計ジャッジ時間 | 5,710 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 TLE * 1 -- * 44 |
ソースコード
MOD = 998244353
def main():
import sys
input = sys.stdin.read().split()
idx = 0
N = int(input[idx]); idx +=1
M = int(input[idx]); idx +=1
k = int(input[idx]); idx +=1
Cs = list(map(int, input[idx:idx+k]))
idx +=k
# Precompute total T
dp0 = [0] * N
dp1 = [0] * N
dp0[0] = 1
total = 0
while True:
new_dp0 = [0] * N
new_dp1 = [0] * N
current_total = 0
# Process a=0
for r in range(N):
if dp0[r] == 0:
continue
for d in range(1,7):
s = r + d
if s >= 2*N:
current_total = (current_total + dp0[r]) % MOD
else:
a_new = s // N
r_new = s % N
if a_new == 0:
new_dp0[r_new] = (new_dp0[r_new] + dp0[r]) % MOD
else:
new_dp1[r_new] = (new_dp1[r_new] + dp0[r]) % MOD
# Process a=1
for r in range(N):
if dp1[r] == 0:
continue
for d in range(1,7):
s = N + r + d
if s >= 2*N:
current_total = (current_total + dp1[r]) % MOD
else:
r_new = (r + d) % N
new_dp1[r_new] = (new_dp1[r_new] + dp1[r]) % MOD
total = (total + current_total) % MOD
# Check if there are no more states to process
if not any(new_dp0) and not any(new_dp1):
break
dp0, dp1 = new_dp0, new_dp1
T = total
# Process each query
for c in Cs:
dp0_avoid = [0] * N
dp1_avoid = [0] * N
dp0_avoid[0] = 1
ans_avoid = 0
current_dp0 = dp0_avoid.copy()
current_dp1 = dp1_avoid.copy()
while True:
new_dp0 = [0] * N
new_dp1 = [0] * N
current_ans = 0
# Process a=0
for r in range(N):
if current_dp0[r] == 0:
continue
for d in range(1,7):
s = r + d
if s >= 2*N:
current_ans = (current_ans + current_dp0[r]) % MOD
else:
a_new = s // N
r_new = s % N
if r_new != c:
if a_new == 0:
new_dp0[r_new] = (new_dp0[r_new] + current_dp0[r]) % MOD
else:
new_dp1[r_new] = (new_dp1[r_new] + current_dp0[r]) % MOD
# Process a=1
for r in range(N):
if current_dp1[r] == 0:
continue
for d in range(1,7):
s = N + r + d
if s >= 2*N:
current_ans = (current_ans + current_dp1[r]) % MOD
else:
r_new = (r + d) % N
if r_new != c:
new_dp1[r_new] = (new_dp1[r_new] + current_dp1[r]) % MOD
ans_avoid = (ans_avoid + current_ans) % MOD
# Check if there are no more states to process
if not any(new_dp0) and not any(new_dp1):
break
current_dp0, current_dp1 = new_dp0, new_dp1
res = (T - ans_avoid) % MOD
print(res)
if __name__ == "__main__":
main()
gew1fw