結果

問題 No.2509 Beam Shateki
ユーザー ntuda
提出日時 2023-10-28 16:54:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,101 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 77,276 KB
最終ジャッジ日時 2024-09-25 16:31:14
合計ジャッジ時間 19,769 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42 WA * 4 RE * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
A = [[0] * (W + 2)]
A += [[0] + list(map(int, input().split())) + [0] for _ in range(H)]
A += [[0] * (W + 2)]
H += 2
W += 2

N = (H + W) * 3
D = [[-1, 1], [0, 1], [1, 1], [1, -1], [1, 0], [1, 1]]
ans = 0
for i in range(N - 1):
    HW = i // (H * 3)
    if HW == 0:
        x = i // 3
        y = 0
    else:
        y = (i - H * 3) // 3
        x = 0
    cnt1 = 0
    P = set()
    dx, dy = D[3 * HW + i % 3]
    x += dx
    y += dy
    while 0 <= x < H and 0 <= y < W and A[x][y] > 0:
        cnt1 += A[x][y]
        P.add((x, y))
        x += dx
        y += dy
    for j in range(i + 1, N):
        HW = j // (H * 3)
        if HW == 0:
            x = j // 3
            y = 0
        else:
            y = (j - H * 3) // 3
            x = 0
        cnt2 = 0
        dx, dy = D[3 * HW + j % 3]
        x += dx
        y += dy
        while 0 <= x < H and 0 <= y < W and A[x][y] > 0:
            if (x, y) not in P:
                cnt2 += A[x][y]
            x += dx
            y += dy
        ans = max(ans, cnt1 + cnt2)
        #print(i,j,cnt1,cnt2)
print(ans)
0