結果

問題 No.1838 Modulo Straight
ユーザー 👑 rin204rin204
提出日時 2022-02-11 23:41:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 739 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 86,708 KB
実行使用メモリ 143,692 KB
最終ジャッジ日時 2023-09-10 06:42:35
合計ジャッジ時間 10,453 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,256 KB
testcase_01 AC 70 ms
71,180 KB
testcase_02 AC 71 ms
71,056 KB
testcase_03 AC 90 ms
76,296 KB
testcase_04 WA -
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 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 160 ms
121,728 KB
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 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 108 ms
98,320 KB
testcase_40 AC 70 ms
71,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

m, k = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
cnt = [0] * m
left = 0
right = 0
plus = [0] * m
mi_cnt = [0] * m
pm = [0] * m
for i, a in enumerate(A):
    c = cnt[a] * m + a
    ans += abs(c - i)
    cnt[a] += 1
    if i <= c:
        left += 1
    else:
        right += 1
        
    l = c // m * m
    r = (c + m) // m * m
    if i <= l:
        plus[a] -= m
    elif i >= r:
        plus[a] += m
    else:
        mi_cnt[a] += 1
        plus[a] += (i - l) - (r - i)
        tmp = (i - a) % m
        pm[tmp] += 1

tot = ans
for i in range(1, m):
    tot += left - right + plus[m - i]
    left += -mi_cnt[m - i] + pm[i]
    right += mi_cnt[m - i] - pm[i]
    ans = min(ans, tot)
    
print(ans // 2)
    
0