結果
問題 | No.270 next_permutation (1) |
ユーザー |
![]() |
提出日時 | 2020-04-01 01:48:19 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 915 bytes |
コンパイル時間 | 223 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 24,112 KB |
最終ジャッジ日時 | 2024-06-25 17:00:57 |
合計ジャッジ時間 | 5,133 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 1 |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from bisect import bisect_left import itertools N, K = map(int, readline().split()) P = [0] + list(map(int, readline().split())) B = [0] + list(map(int, readline().split())) D = [sum(abs(x - y) for x, y in zip(P, B))] for _ in range(K - 1): diff = 0 Q = [] while P[-2] > P[-1]: x = P.pop() diff -= abs(x - B[len(P)]) Q.append(x) x = P.pop() diff -= abs(x - B[len(P)]) Q.append(x) if not P[-1]: P = list(range(N + 1)) D.append(sum(abs(x - y) for x, y in zip(P, B))) continue p=P.pop() diff -= abs(p - B[len(P)]) n=bisect_left(Q, p) for x in itertools.chain([Q[n]], Q[:n], [p], Q[n + 1:]): diff += abs(x - B[len(P)]) P.append(x) D.append(D[-1] + diff) print(sum(D))