結果
問題 | No.335 門松宝くじ |
ユーザー | rpy3cpp |
提出日時 | 2016-01-16 01:12:18 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,619 ms / 2,000 ms |
コード長 | 2,370 bytes |
コンパイル時間 | 144 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 21,320 KB |
最終ジャッジ日時 | 2024-09-19 19:47:01 |
合計ジャッジ時間 | 11,629 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 27 ms
11,008 KB |
testcase_01 | AC | 30 ms
11,136 KB |
testcase_02 | AC | 31 ms
11,136 KB |
testcase_03 | AC | 27 ms
11,008 KB |
testcase_04 | AC | 28 ms
10,880 KB |
testcase_05 | AC | 437 ms
14,976 KB |
testcase_06 | AC | 624 ms
14,976 KB |
testcase_07 | AC | 1,100 ms
21,016 KB |
testcase_08 | AC | 635 ms
21,020 KB |
testcase_09 | AC | 1,599 ms
21,060 KB |
testcase_10 | AC | 1,619 ms
21,060 KB |
testcase_11 | AC | 1,600 ms
21,320 KB |
testcase_12 | AC | 1,608 ms
21,044 KB |
testcase_13 | AC | 1,615 ms
21,172 KB |
ソースコード
# -*- coding: utf-8 -*- """ Created on Sat Jan 16 00:04:09 2016 @author: NEC-PCuser """ 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))