結果
問題 | No.1867 Partitions and Inversions |
ユーザー | shiomusubi496 |
提出日時 | 2022-03-02 16:28:52 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,201 bytes |
コンパイル時間 | 262 ms |
コンパイル使用メモリ | 11,160 KB |
実行使用メモリ | 8,384 KB |
最終ジャッジ日時 | 2023-09-23 09:01:36 |
合計ジャッジ時間 | 7,331 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
8,384 KB |
testcase_01 | AC | 17 ms
8,340 KB |
testcase_02 | TLE | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
testcase_60 | -- | - |
testcase_61 | -- | - |
testcase_62 | -- | - |
testcase_63 | -- | - |
testcase_64 | -- | - |
testcase_65 | -- | - |
testcase_66 | -- | - |
testcase_67 | -- | - |
ソースコード
class Manager: class node: def __init__(self, a, b, c) -> None: self.i = a self.m = b self.limit = c def __init__(self, D) -> None: self.n = len(D) self.C = D self.data = [] assert len(D) + 1 == len(D[0]) def add(self, i, m) -> None: if not self.data: self.data.append(self.node(i, m, self.n)) return else: while self.data[-1].limit < i + 1: self.data.pop() d = self.data[-1] if self.C[d.i][i + 1] + d.m < self.C[i][i + 1] + m: return pushed = False while self.data: d = self.data[-1] if self.C[d.i][d.limit] + d.m > self.C[i][d.limit] + m: self.data.pop() else: ok = i + 1 ng = d.limit while ng - ok > 1: mid = (ok + ng) >> 1 if self.C[d.i][mid] + d.m > self.C[i][mid] + m: ok = mid else: ng = mid self.data.append(self.node(i, m, ok)) pushed = True break if not pushed: self.data.append(self.node(i, m, self.n)) def get_min(self, x) -> int: while self.data[-1].limit < x: self.data.pop() d = self.data[-1] return self.C[d.i][x] + d.m def clear_log(self) -> None: while self.data: self.data.pop() N = int(input()) P = list(map(int, input().split())) D = [[0] * (N + 1) for _ in range(N)] for i in range(N - 1): R = [0] * (N + 1) for j in range(i + 1): R[P[j]] += 1 for j in range(1, N + 1): R[j] += R[j - 1] sm = 0 for j in range(i + 1, N): sm += R[N] - R[P[j]] D[i + 1][j + 1] = sm m = Manager(D) dp = [[N * N] * (N + 1) for _ in range(N + 1)] dp[0][0] = 0 for j in range(N): m.add(j, dp[j][j]) for i in range(j + 1, N + 1): dp[i][j + 1] = m.get_min(i) if i != N: m.add(i, dp[i][j]) m.clear_log() for i in range(1, N + 1): print(dp[N][i])