結果

問題 No.335 門松宝くじ
ユーザー chocorusk
提出日時 2020-09-25 20:07:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 874 bytes
コンパイル時間 556 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 91,392 KB
最終ジャッジ日時 2024-06-28 05:58:32
合計ジャッジ時間 2,570 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline
n, m=map(int, readline().split())
def solve1(a, c):
    mn=n+1
    for i, x in enumerate(a):
        mx=0
        for y in a[i+1:]:
            if x>y and mx>x:c[x][y]=max(mx, c[x][y])
            elif x>y and mn<x:c[x][y]=max(x, c[x][y])
            mx=max(mx, y)
        mn=min(mn, x)
    mx=0
    for i in range(n-1, -1, -1):
        y=a[i]
        mn=n+1
        for j in range(i-1, -1, -1):
            x=a[j]
            if x>y and mx>y:
                z=max(x, mx)
                c[x][y]=max(z, c[x][y])
            elif x>y and mn<y:c[x][y]=max(x, c[x][y])
            mn=min(mn, x)
        mx=max(mx, y)
def solve(a):
    c=[[0]*(n+1) for _ in range(n+1)]
    solve1(a, c)
    solve1(a[::-1], c)
    return sum(sum(ci) for ci in c)
ans=[solve(list(map(int, readline().split()))) for i in range(m)]
print(ans.index(max(ans)))
0