結果

問題 No.2509 Beam Shateki
ユーザー ntudantuda
提出日時 2023-12-14 19:36:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 2,251 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,436 KB
最終ジャッジ日時 2023-12-14 19:36:47
合計ジャッジ時間 7,626 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 95 ms
76,092 KB
testcase_04 AC 92 ms
76,236 KB
testcase_05 AC 91 ms
76,236 KB
testcase_06 AC 96 ms
76,236 KB
testcase_07 AC 92 ms
76,292 KB
testcase_08 AC 98 ms
76,236 KB
testcase_09 AC 92 ms
76,236 KB
testcase_10 AC 91 ms
76,236 KB
testcase_11 AC 92 ms
76,236 KB
testcase_12 AC 95 ms
76,236 KB
testcase_13 AC 107 ms
76,428 KB
testcase_14 AC 105 ms
76,420 KB
testcase_15 AC 104 ms
76,428 KB
testcase_16 AC 105 ms
76,436 KB
testcase_17 AC 104 ms
76,424 KB
testcase_18 AC 108 ms
76,424 KB
testcase_19 AC 106 ms
76,424 KB
testcase_20 AC 105 ms
76,424 KB
testcase_21 AC 107 ms
76,436 KB
testcase_22 AC 106 ms
76,424 KB
testcase_23 AC 106 ms
76,424 KB
testcase_24 AC 105 ms
76,428 KB
testcase_25 AC 103 ms
76,428 KB
testcase_26 AC 104 ms
76,424 KB
testcase_27 AC 104 ms
76,424 KB
testcase_28 AC 109 ms
76,424 KB
testcase_29 AC 105 ms
76,424 KB
testcase_30 AC 105 ms
76,424 KB
testcase_31 AC 105 ms
76,420 KB
testcase_32 AC 105 ms
76,424 KB
testcase_33 AC 69 ms
72,376 KB
testcase_34 AC 94 ms
76,220 KB
testcase_35 AC 98 ms
76,272 KB
testcase_36 AC 86 ms
76,096 KB
testcase_37 AC 56 ms
66,368 KB
testcase_38 AC 95 ms
76,296 KB
testcase_39 AC 85 ms
76,100 KB
testcase_40 AC 98 ms
76,224 KB
testcase_41 AC 51 ms
63,900 KB
testcase_42 AC 88 ms
76,228 KB
testcase_43 AC 99 ms
76,356 KB
testcase_44 AC 99 ms
76,388 KB
testcase_45 AC 84 ms
76,232 KB
testcase_46 AC 85 ms
76,224 KB
testcase_47 AC 101 ms
76,408 KB
testcase_48 AC 103 ms
76,224 KB
testcase_49 AC 92 ms
76,100 KB
testcase_50 AC 98 ms
76,312 KB
testcase_51 AC 67 ms
70,300 KB
testcase_52 AC 94 ms
76,104 KB
testcase_53 AC 37 ms
53,460 KB
testcase_54 AC 37 ms
53,460 KB
testcase_55 AC 38 ms
53,460 KB
testcase_56 AC 38 ms
53,460 KB
testcase_57 AC 38 ms
53,460 KB
testcase_58 AC 38 ms
53,460 KB
testcase_59 AC 37 ms
53,460 KB
testcase_60 AC 38 ms
53,460 KB
testcase_61 AC 38 ms
53,460 KB
testcase_62 AC 37 ms
53,460 KB
testcase_63 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
W = 2 * H + W - 2
A = [[0] * (H - 1) + list(map(int, input().split())) + [0] * (H - 1) for _ in range(H)]
N = W * 3 + H
D = [(1, -1), (1, 0), (1, 1), (0, 1)]
S = [0] * N
for i in range(N):
    if i < W * 3:
        y = i // 3
        x = 0
        d = i % 3
    else:
        y = 0
        x = i - W * 3
        d = 3
    tmp = 0
    while 0 <= x < H and 0 <= y < W:
        tmp += A[x][y]
        x += D[d][0]
        y += D[d][1]
    S[i] = tmp
#for i in range(H):
    #print(*A[i])
#print(S)
ans = 0
for i in range(N - 1):
    if i < W * 3:
        y1 = i // 3
        x1 = 0
        d1 = i % 3
    else:
        y1 = 0
        x1 = i - W * 3
        d1 = 3
    for j in range(i + 1, N):
        tmp = S[i] + S[j]
        if j < W * 3:
            y2 = j // 3
            x2 = 0
            d2 = j % 3
        else:
            x2 = j - W * 3
            y2 = 0
            d2 = 3
        if d2 == 3:
            if d1 == 0:
                if 0 <= y1 - x2 < W:
                    tmp -= A[x2][y1 - x2]
            elif d1 == 1:
                tmp -= A[x2][y1]
            elif d1 == 2:
                if 0 <= y1 + x2 < W:
                    tmp -= A[x2][y1 + x2]
            ans = max(ans, tmp)
            #print(i,j,":","a",x1,y1,d1,x2,y2,d2,":",S[i]+S[j],tmp)
            continue
        if y1 == y2:
            tmp -= A[0][y1]
            #print(i,j,":","b",x1,y1,d1,x2,y2,d2,":",S[i]+S[j],tmp)
            ans = max(ans, tmp)
            continue
        if d2 == 0:
            if d1 == 2:
                yt = y2 - y1
                if yt % 2 == 0 and yt // 2 < H:
                    tmp -= A[yt // 2][(y2 + y1) // 2]
            elif d1 == 1:
                if y2 - y1 < H:
                    tmp -= A[y2 - y1][y1]
            #print(i,j,":","c",x1,y1,d1,x2,y2,d2,":",S[i]+S[j],tmp)
            ans = max(ans, tmp)
            continue
        if d2 == 1 and d1 == 2:
            if y2 - y1 < H:
                tmp -= A[y2 - y1][y2]
                #print(i, j, ":","d", x1, y1, d1, x2, y2, d2, ":", S[i] + S[j], tmp)
                ans = max(ans, tmp)
                continue
        #print(i, j, ":","e", x1, y1, d1, x2, y2, d2, ":", S[i] + S[j], tmp)
        ans = max(ans, tmp)
print(ans)
0