結果
問題 | No.335 門松宝くじ |
ユーザー | soupesuteaka |
提出日時 | 2016-02-25 17:48:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 431 ms / 2,000 ms |
コード長 | 2,406 bytes |
コンパイル時間 | 145 ms |
コンパイル使用メモリ | 82,388 KB |
実行使用メモリ | 92,516 KB |
最終ジャッジ日時 | 2024-09-22 13:42:32 |
合計ジャッジ時間 | 4,224 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
65,812 KB |
testcase_01 | AC | 58 ms
64,216 KB |
testcase_02 | AC | 59 ms
65,812 KB |
testcase_03 | AC | 55 ms
65,272 KB |
testcase_04 | AC | 55 ms
64,548 KB |
testcase_05 | AC | 242 ms
84,164 KB |
testcase_06 | AC | 333 ms
85,760 KB |
testcase_07 | AC | 310 ms
91,284 KB |
testcase_08 | AC | 162 ms
88,472 KB |
testcase_09 | AC | 419 ms
91,784 KB |
testcase_10 | AC | 424 ms
92,312 KB |
testcase_11 | AC | 423 ms
92,516 KB |
testcase_12 | AC | 431 ms
92,180 KB |
testcase_13 | AC | 418 ms
91,608 KB |
ソースコード
#coding: UTF-8 import sys import re import itertools """ defs """ """ main """ N, M = map(int, input().split()) E = list ( list( map(int,input().split()) ) for _ in range(M) ) idx = 0 maxex = 0 leftmins = [0]*(N) rightmins = [0]*(N) leftmaxs = [0]*(N) rightmaxs = [0]*(N) midmins = list ( [0] * (N) for _ in range(N) ) midmaxs = list ( [0] * (N) for _ in range(N) ) for m in range(M): leftmins[0] = E[m][0] for i in range(1, N): leftmins[i] = min(leftmins[i-1],E[m][i]) rightmins[N-1] = E[m][N-1] for i in reversed(range(0,N-1)): rightmins[i] = min(rightmins[i+1],E[m][i]) leftmaxs[0] = E[m][0] for i in range(1, N): leftmaxs[i] = max(leftmaxs[i-1],E[m][i]) rightmaxs[N-1] = E[m][N-1] for i in reversed(range(0,N-1)): rightmaxs[i] = max(rightmaxs[i+1],E[m][i]) for i in range(N): midmins[i][i] = E[m][i] midmaxs[i][i] = E[m][i] for i in range(0,N): for l in range(1,N): if (i+l>=N): break midmins[i][i+l] = min(midmins[i][i+l-1],E[m][i+l]) midmaxs[i][i+l] = max(midmaxs[i][i+l-1],E[m][i+l]) ans = 0 for i in range(0, N): for j in range(i+1, N): maximam = 0 if (E[m][i] < E[m][j]): if (i==0): tmp = 0 else: tmp = leftmaxs[i-1] if (tmp > E[m][i]): maximam = max(E[m][i],E[m][j],tmp, maximam) if (i+1>j-1): tmp = N+1 else: tmp = midmins[i+1][j-1] if (tmp < E[m][i]): maximam = max(E[m][i],E[m][j],tmp, maximam) if (i+1>j-1): tmp = 0 else: tmp = midmaxs[i+1][j-1] if (tmp > E[m][j]): maximam = max(E[m][i],E[m][j],tmp, maximam) if (j+1>=N): tmp = N+1 else: tmp = rightmins[j+1] if (tmp < E[m][j]): maximam = max(E[m][i],E[m][j],tmp, maximam) else: if (i==0): tmp = N+1 else: tmp = leftmins[i-1] if (tmp < E[m][i]): maximam = max(E[m][i],E[m][j],tmp, maximam) if (i+1>j-1): tmp = 0 else: tmp = midmaxs[i+1][j-1] if (tmp > E[m][i]): maximam = max(E[m][i],E[m][j],tmp, maximam) if (i+1>j-1): tmp = N+1 else: tmp = midmins[i+1][j-1] if (tmp < E[m][j]): maximam = max(E[m][i],E[m][j],tmp, maximam) if (j+1>=N): tmp = 0 else: tmp = rightmaxs[j+1] if (tmp > E[m][j]): maximam = max(E[m][i],E[m][j],tmp, maximam) ans += maximam expectation = ans if (idx==-1 or expectation > maxex): idx = m maxex = expectation print (idx)