結果
問題 | No.335 門松宝くじ |
ユーザー | rpy3cpp |
提出日時 | 2016-01-16 01:13:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 193 ms / 2,000 ms |
コード長 | 2,280 bytes |
コンパイル時間 | 272 ms |
コンパイル使用メモリ | 82,480 KB |
実行使用メモリ | 107,468 KB |
最終ジャッジ日時 | 2024-09-19 19:48:16 |
合計ジャッジ時間 | 2,711 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
53,544 KB |
testcase_01 | AC | 34 ms
53,568 KB |
testcase_02 | AC | 36 ms
53,140 KB |
testcase_03 | AC | 36 ms
53,292 KB |
testcase_04 | AC | 36 ms
52,944 KB |
testcase_05 | AC | 131 ms
82,024 KB |
testcase_06 | AC | 148 ms
89,272 KB |
testcase_07 | AC | 158 ms
97,156 KB |
testcase_08 | AC | 108 ms
96,648 KB |
testcase_09 | AC | 176 ms
107,180 KB |
testcase_10 | AC | 182 ms
107,372 KB |
testcase_11 | AC | 175 ms
107,468 KB |
testcase_12 | AC | 192 ms
107,280 KB |
testcase_13 | AC | 193 ms
107,268 KB |
ソースコード
def calc_score(E, N): maxLeft, minLeft = calc_max_min_left(E) maxRight, minRight = calc_max_min_right(E) maxMid, minMid = calc_max_min_mid(E) score = 0 for L in range(N-1): if L: maxL = maxLeft[L - 1] minL = minLeft[L - 1] else: maxL = 0 minL = N + 1 EL = E[L] maxMidLp = maxMid[L + 1] minMidLp = minMid[L + 1] for R in range(L + 1, N): ER = E[R] s = 0 maxM = maxMidLp[R - 1] if maxM > EL and maxM > ER: s = maxM minM = minMidLp[R - 1] if minM < EL and minM < ER: s = max(s, EL, ER) if EL < ER: if maxL > EL: s = max(s, ER, maxL) if R < N - 1: minR = minRight[R + 1] if minR < ER: s = max(s, ER) else: if minL < EL: s = max(s, EL) if R < N - 1: maxR = maxRight[R + 1] if maxR > E[R]: s = max(s, EL, maxR) score += s return score def calc_max_min_mid(E): n = len(E) maxMid = [[0] * n for _ in range(n)] minMid = [[n + 1] * n for _ in range(n)] for L in range(n - 1): maxMidL = maxMid[L] minMidL = minMid[L] maxMidL[L] = E[L] minMidL[L] = E[L] for R in range(L + 1, n): maxMidL[R] = max(maxMidL[R - 1], E[R]) minMidL[R] = min(minMidL[R - 1], E[R]) return maxMid, minMid def calc_max_min_left(E): maxL = 0 minL = 1000 maxLeft = [] minLeft = [] for e in E: maxL = max(maxL, e) minL = min(minL, e) maxLeft.append(maxL) minLeft.append(minL) return maxLeft, minLeft def calc_max_min_right(E): revE = E[:] revE.reverse() maxRight, minRight = calc_max_min_left(revE) maxRight.reverse() minRight.reverse() return maxRight, minRight N, M = map(int, input().split()) Es = [] for m in range(M): Es.append(list(map(int, input().split()))) scores = [calc_score(E, N) for E in Es] maxS = max(scores) print(scores.index(maxS))