結果
| 問題 |
No.1720 Division Permutation
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 18:13:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,211 bytes |
| コンパイル時間 | 272 ms |
| コンパイル使用メモリ | 82,380 KB |
| 実行使用メモリ | 55,920 KB |
| 最終ジャッジ日時 | 2025-06-12 18:14:50 |
| 合計ジャッジ時間 | 7,906 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 TLE * 1 -- * 49 |
ソースコード
MOD = 998244353
n, k = map(int, input().split())
p = list(map(int, input().split()))
dp = [[0] * (k + 1) for _ in range(n + 1)]
dp[0][0] = 1
from collections import deque
for i in range(1, n + 1):
min_deque = deque()
max_deque = deque()
# j ranges from i-1 down to 0 (window [j..i-1] in 0-based)
# we need to check window [j..i-1] (converted to 1-based [j+1..i])
for j in range(i - 1, -1, -1):
current = p[j]
# Maintain min_deque and max_deque for the current window [j..i-1]
while min_deque and p[min_deque[-1]] >= current:
min_deque.pop()
min_deque.append(j)
while max_deque and p[max_deque[-1]] <= current:
max_deque.pop()
max_deque.append(j)
# Compute current min and max
current_min = p[min_deque[0]]
current_max = p[max_deque[0]]
window_length = i - j
if current_max - current_min + 1 == window_length:
# This window [j..i-1] (0-based) corresponds to [j+1..i] in 1-based
for x in range(1, k + 1):
dp[i][x] = (dp[i][x] + dp[j][x - 1]) % MOD
ans = [dp[n][x] % MOD for x in range(1, k + 1)]
print('\n'.join(map(str, ans)))
gew1fw