結果

問題 No.335 門松宝くじ
ユーザー rpy3cpprpy3cpp
提出日時 2016-01-16 00:34:39
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 1,538 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 12,144 KB
実行使用メモリ 10,492 KB
最終ジャッジ日時 2023-10-19 23:51:53
合計ジャッジ時間 4,555 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,256 KB
testcase_01 AC 33 ms
10,256 KB
testcase_02 AC 29 ms
10,256 KB
testcase_03 AC 30 ms
10,256 KB
testcase_04 AC 30 ms
10,256 KB
testcase_05 AC 163 ms
10,324 KB
testcase_06 AC 231 ms
10,344 KB
testcase_07 AC 375 ms
10,412 KB
testcase_08 AC 154 ms
10,412 KB
testcase_09 AC 550 ms
10,424 KB
testcase_10 AC 548 ms
10,424 KB
testcase_11 WA -
testcase_12 AC 555 ms
10,424 KB
testcase_13 AC 549 ms
10,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def calc_score(E, N):
    maxLeft, minLeft = calc_max_min_left(E)
    maxRight, minRight = calc_max_min_right(E)
    score = 0
    for L in range(N-1):
        EL = E[L]
        for R in range(L + 1, N):
            if EL < E[R]:
                s = 0
                if L:
                    maxL = maxLeft[L - 1]
                    if maxL > EL:
                        s = max(E[R], maxL)
                if R < N - 1:
                    minR = minRight[R + 1]
                    if minR < E[R]:
                        s = max(s, E[R])
            else:
                s = 0
                if L:
                    minL = minLeft[L - 1]
                    if minL < EL:
                        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_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))
0