結果

問題 No.335 門松宝くじ
ユーザー mkawa2mkawa2
提出日時 2020-02-28 18:57:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 347 ms / 2,000 ms
コード長 1,983 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-21 17:39:56
合計ジャッジ時間 2,717 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,880 KB
testcase_01 AC 27 ms
11,008 KB
testcase_02 AC 27 ms
10,880 KB
testcase_03 AC 29 ms
10,880 KB
testcase_04 AC 29 ms
10,880 KB
testcase_05 AC 57 ms
10,880 KB
testcase_06 AC 71 ms
11,008 KB
testcase_07 AC 105 ms
11,008 KB
testcase_08 AC 347 ms
11,008 KB
testcase_09 AC 142 ms
11,008 KB
testcase_10 AC 145 ms
11,008 KB
testcase_11 AC 145 ms
11,008 KB
testcase_12 AC 141 ms
11,136 KB
testcase_13 AC 147 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

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]

class SparseTable:
    def __init__(self, aa):
        w = len(aa)
        h = w.bit_length()
        table = [aa] + [[-1] * w for _ in range(h - 1)]
        tablei1 = table[0]
        for i in range(1, h):
            tablei = table[i]
            for j in range(w-(1<<i)+1):
                rj = j + (1 << (i - 1))
                tablei[j] = min(tablei1[j], tablei1[rj])
            tablei1 = tablei
        self.table = table

    def min(self, l, r):
        i = (r - l).bit_length() - 1
        tablei = self.table[i]
        Lmin = tablei[l]
        Rmin = tablei[r - (1 << i)]
        if Lmin < Rmin: Rmin = Lmin
        return Rmin

def main():
    inf=10**9
    n,m=MI()
    ss=[]
    for _ in range(m):
        ee=LI()
        st=SparseTable(ee)
        lmx = [0] * n
        rmx = [0] * n
        mx=-inf
        for i,e in enumerate(ee):
            lmx[i]=mx
            if e>mx:mx=e
        mx=-inf
        for i,e in enumerate(ee[::-1]):
            rmx[n-1-i]=mx
            if e>mx:mx=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 st.min(j,n)<b or st.min(i,j)<a:s+=b
                else:
                    if rmx[i]>a:s+=rmx[i]
                    elif rmx[j]>b or st.min(0,i+1)<a or st.min(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