結果
問題 | No.2509 Beam Shateki |
ユーザー | なえしら |
提出日時 | 2024-06-11 23:13:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 235 ms / 2,000 ms |
コード長 | 1,978 bytes |
コンパイル時間 | 285 ms |
コンパイル使用メモリ | 82,080 KB |
実行使用メモリ | 79,700 KB |
最終ジャッジ日時 | 2024-06-11 23:13:31 |
合計ジャッジ時間 | 11,109 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,564 KB |
testcase_01 | AC | 38 ms
52,952 KB |
testcase_02 | AC | 37 ms
52,744 KB |
testcase_03 | AC | 148 ms
77,680 KB |
testcase_04 | AC | 157 ms
78,072 KB |
testcase_05 | AC | 153 ms
78,060 KB |
testcase_06 | AC | 163 ms
77,688 KB |
testcase_07 | AC | 150 ms
77,684 KB |
testcase_08 | AC | 155 ms
77,804 KB |
testcase_09 | AC | 150 ms
77,532 KB |
testcase_10 | AC | 167 ms
77,916 KB |
testcase_11 | AC | 151 ms
77,812 KB |
testcase_12 | AC | 147 ms
77,560 KB |
testcase_13 | AC | 201 ms
78,504 KB |
testcase_14 | AC | 171 ms
78,140 KB |
testcase_15 | AC | 173 ms
78,372 KB |
testcase_16 | AC | 206 ms
79,020 KB |
testcase_17 | AC | 178 ms
78,168 KB |
testcase_18 | AC | 170 ms
78,124 KB |
testcase_19 | AC | 181 ms
78,128 KB |
testcase_20 | AC | 211 ms
78,768 KB |
testcase_21 | AC | 235 ms
78,676 KB |
testcase_22 | AC | 173 ms
78,116 KB |
testcase_23 | AC | 175 ms
78,380 KB |
testcase_24 | AC | 174 ms
78,124 KB |
testcase_25 | AC | 175 ms
78,152 KB |
testcase_26 | AC | 217 ms
79,408 KB |
testcase_27 | AC | 203 ms
79,268 KB |
testcase_28 | AC | 176 ms
78,380 KB |
testcase_29 | AC | 172 ms
78,008 KB |
testcase_30 | AC | 175 ms
78,148 KB |
testcase_31 | AC | 214 ms
79,700 KB |
testcase_32 | AC | 175 ms
78,428 KB |
testcase_33 | AC | 97 ms
76,336 KB |
testcase_34 | AC | 156 ms
77,776 KB |
testcase_35 | AC | 168 ms
78,204 KB |
testcase_36 | AC | 154 ms
77,876 KB |
testcase_37 | AC | 125 ms
77,232 KB |
testcase_38 | AC | 165 ms
78,436 KB |
testcase_39 | AC | 152 ms
78,388 KB |
testcase_40 | AC | 160 ms
77,988 KB |
testcase_41 | AC | 55 ms
65,972 KB |
testcase_42 | AC | 154 ms
78,112 KB |
testcase_43 | AC | 169 ms
77,956 KB |
testcase_44 | AC | 172 ms
78,544 KB |
testcase_45 | AC | 140 ms
77,476 KB |
testcase_46 | AC | 164 ms
77,892 KB |
testcase_47 | AC | 174 ms
78,392 KB |
testcase_48 | AC | 156 ms
77,888 KB |
testcase_49 | AC | 168 ms
77,704 KB |
testcase_50 | AC | 165 ms
78,268 KB |
testcase_51 | AC | 105 ms
76,196 KB |
testcase_52 | AC | 161 ms
78,188 KB |
testcase_53 | AC | 39 ms
53,196 KB |
testcase_54 | AC | 39 ms
54,608 KB |
testcase_55 | AC | 40 ms
53,472 KB |
testcase_56 | AC | 40 ms
54,536 KB |
testcase_57 | AC | 40 ms
54,028 KB |
testcase_58 | AC | 39 ms
54,928 KB |
testcase_59 | AC | 39 ms
54,092 KB |
testcase_60 | AC | 39 ms
54,052 KB |
testcase_61 | AC | 39 ms
53,688 KB |
testcase_62 | AC | 39 ms
53,676 KB |
testcase_63 | AC | 40 ms
54,652 KB |
ソースコード
class Max2: def __init__(self, fst_key=-1, fst_val=-9*10**18, snd_key=-2, snd_val=-9*10**18): self.fst_key, self.fst_val = fst_key, fst_val self.snd_key, self.snd_val = snd_key, snd_val def chmax2(self, key, val): if key == self.fst_key: self.fst_val = max(self.fst_val, val) elif val > self.fst_val: self.snd_key, self.snd_val = self.fst_key, self.fst_val self.fst_key, self.fst_val = key, val elif val > self.snd_val: self.snd_key, self.snd_val = key, val from itertools import product H, W = map(int, input().split()) A = [[0]*(2*H+W) for _ in range(2*W+H)] for i in range(H): A[W+i][H:H+W] = list(map(int, input().split())) row, col = [0]*(2*W+H), [0]*(2*H+W) diag, skew = [0]*(3*H+3*W), [0]*(3*H+3*W) for i, j in product(range(2*W+H), range(2*H+W)): row[i] += A[i][j]; col[j] += A[i][j] diag[i-j] += A[i][j]; skew[i+j] += A[i][j] row_max2, col_max2 = Max2(), Max2() diag_max2, skew_max2 = Max2(), Max2() for i in range(2*W+H): row_max2.chmax2(i, row[i]) for j in range(2*H+W): col_max2.chmax2(j, col[j]) for k in range(3*H+3*W): diag_max2.chmax2(k, diag[k]) for l in range(3*H+3*W): skew_max2.chmax2(l, skew[l]) ans = max( row_max2.fst_val + row_max2.snd_val, col_max2.fst_val + col_max2.snd_val, diag_max2.fst_val + diag_max2.snd_val, skew_max2.fst_val + skew_max2.snd_val ) for i, j in product(range(2*W+H), range(2*H+W)): max2 = Max2(0, row[i]); max2.chmax2(1, col[j]) max2.chmax2(2, diag[i-j]); max2.chmax2(3, skew[i+j]) ans = max(ans, max2.fst_val + max2.snd_val - A[i][j]) even_diag_max = odd_diag_max = 0 even_skew_max = odd_skew_max = 0 for k in range(3*H+3*W): if k%2: odd_diag_max = max(odd_diag_max, diag[k]) else: even_diag_max = max(even_diag_max, diag[k]) for l in range(3*H+3*W): if l%2: odd_skew_max = max(odd_skew_max, skew[l]) else: even_skew_max = max(even_skew_max, skew[l]) ans = max(ans, even_diag_max + odd_skew_max, even_skew_max + odd_diag_max ) print(ans)