結果
問題 | No.1391 ±1 Abs Sum |
ユーザー | 👑 terry_u16 |
提出日時 | 2021-02-12 22:32:14 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 762 bytes |
コンパイル時間 | 277 ms |
コンパイル使用メモリ | 87,276 KB |
実行使用メモリ | 107,972 KB |
最終ジャッジ日時 | 2023-09-27 05:12:57 |
合計ジャッジ時間 | 5,991 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 61 ms
71,572 KB |
testcase_01 | AC | 61 ms
71,476 KB |
testcase_02 | AC | 63 ms
71,612 KB |
testcase_03 | AC | 64 ms
71,528 KB |
testcase_04 | AC | 61 ms
71,632 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 108 ms
94,004 KB |
testcase_15 | WA | - |
testcase_16 | AC | 120 ms
102,148 KB |
testcase_17 | WA | - |
testcase_18 | AC | 131 ms
100,148 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 136 ms
103,748 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 60 ms
71,604 KB |
testcase_36 | AC | 117 ms
102,088 KB |
ソースコード
n, k = map(int, input().split()) a = list(map(int, input().split())) current = 0 for i in range(n): if i < k: current += abs(a[i] - a[0]) else: current -= abs(a[i] - a[0]) minimum = current nextSub = k for i in range(1, n): plus = n - max(nextSub - 1, i) + i - min(i, nextSub - k) minus = n - plus current += (plus - minus) * abs(a[i] - a[i - 1]) while nextSub < n: left = a[nextSub - k] right = a[nextSub] leftDiff = abs(left - a[i]) rightDiff = abs(right - a[i]) if leftDiff > rightDiff: current -= 2 * leftDiff current += 2 * rightDiff nextSub += 1 else: break minimum = min(minimum, current) print(minimum)