提出 #53038335


ソースコード 拡げる

from collections import deque


def Sliding_Window_Minimum(A, L):
    ans = []
    dq = deque()
    for i, a in enumerate(A):
        while dq and a <= dq[-1][1]:
            dq.pop()
        dq.append([i, a])
        if i >= L - 1:
            ans.append(dq[0][1])
        if dq and dq[0][0] <= i + 1 - L:
            dq.popleft()
    return ans


N, K = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
Q = [0] * N
for i in range(N):
    Q[P[i]] = i

mn_pos = Sliding_Window_Minimum(Q, K)
mx_pos = Sliding_Window_Minimum([-i for i in Q], K)

ans = N
for mn, mx in zip(mn_pos, mx_pos):
    ans = min(ans, -mx - mn)
print(ans)

提出情報

提出日時
問題 D - Permutation Subsequence
ユーザ toam
言語 Python (PyPy 3.10-v7.3.12)
得点 425
コード長 685 Byte
結果 AC
実行時間 138 ms
メモリ 124200 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 425 / 425
結果
AC × 3
AC × 28
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_handmade_00.txt, 03_handmade_01.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 66 ms 76788 KiB
00_sample_01.txt AC 67 ms 76996 KiB
00_sample_02.txt AC 67 ms 76872 KiB
01_random_00.txt AC 113 ms 99468 KiB
01_random_01.txt AC 135 ms 111660 KiB
01_random_02.txt AC 95 ms 93620 KiB
01_random_03.txt AC 128 ms 111452 KiB
01_random_04.txt AC 131 ms 110504 KiB
01_random_05.txt AC 134 ms 111664 KiB
01_random_06.txt AC 121 ms 104880 KiB
01_random_07.txt AC 123 ms 111240 KiB
01_random_08.txt AC 118 ms 106068 KiB
01_random_09.txt AC 130 ms 111264 KiB
01_random_10.txt AC 91 ms 89804 KiB
01_random_11.txt AC 131 ms 111068 KiB
01_random_12.txt AC 87 ms 85672 KiB
01_random_13.txt AC 132 ms 111112 KiB
01_random_14.txt AC 95 ms 93632 KiB
01_random_15.txt AC 119 ms 121412 KiB
01_random_16.txt AC 118 ms 110980 KiB
01_random_17.txt AC 67 ms 76988 KiB
02_random2_00.txt AC 130 ms 124200 KiB
02_random2_01.txt AC 125 ms 111476 KiB
02_random2_02.txt AC 138 ms 114192 KiB
02_random2_03.txt AC 136 ms 112724 KiB
02_random2_04.txt AC 123 ms 111240 KiB
03_handmade_00.txt AC 118 ms 111764 KiB
03_handmade_01.txt AC 136 ms 116400 KiB