結果

問題 No.335 門松宝くじ
ユーザー mkawa2mkawa2
提出日時 2020-02-28 18:51:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,476 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2024-04-21 17:39:18
合計ジャッジ時間 4,130 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
16,384 KB
testcase_01 AC 26 ms
10,880 KB
testcase_02 AC 26 ms
10,752 KB
testcase_03 AC 25 ms
10,752 KB
testcase_04 AC 26 ms
10,752 KB
testcase_05 AC 56 ms
10,880 KB
testcase_06 AC 75 ms
10,880 KB
testcase_07 AC 100 ms
10,880 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    inf=10**9
    n,m=MI()
    ss=[]
    for _ in range(m):
        ee=LI()
        lmx = [0] * n
        lmn = [0] * n
        rmx = [0] * n
        rmn = [0] * n
        mx=-inf
        mn=inf
        for i,e in enumerate(ee):
            lmx[i]=mx
            lmn[i]=mn
            if e>mx:mx=e
            if e<mn:mn=e
        mx=-inf
        mn=inf
        for i,e in enumerate(ee[::-1]):
            rmx[n-1-i]=mx
            rmn[n-1-i]=mn
            if e>mx:mx=e
            if e<mn:mn=e
        #print(lmx)
        #print(lmn)
        #print(rmx)
        #print(rmn)
        s=0
        for j in range(n):
            for i in range(j):
                a,b=ee[i],ee[j]
                if a<b:
                    if lmx[j]>b:s+=lmx[j]
                    elif lmx[i]>a or rmn[j]<b or min(ee[i:j])<a:s+=b
                else:
                    if rmx[i]>a:s+=rmx[i]
                    elif rmx[j]>b or lmn[i]<a or min(ee[i:j])<b:s+=a
        ss.append(s)
    #print(ss)
    mx=max(ss)
    for i in range(m):
        if ss[i]==mx:
            print(i)
            break

main()
0