結果

問題 No.2509 Beam Shateki
ユーザー ID 21712
提出日時 2025-05-02 18:03:34
言語 Go
(1.23.4)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 1,574 bytes
コンパイル時間 12,901 ms
コンパイル使用メモリ 239,588 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-05-02 18:03:57
合計ジャッジ時間 20,884 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import . "fmt"

func main() {
	var h, w int
	Scan(&h, &w)
	grid := make([][]int, h+2)
	for i := range grid {
		grid[i] = make([]int, w+2)
	}
	for i := 1; i <= h; i++ {
		for j := 1; j <= w; j++ {
			Scan(&grid[i][j])
		}
	}
	type Pos struct {
		row, col int
	}
	beams := [][]*Pos{}
	for i := 1; i <= h; i++ {
		b := []*Pos{}
		for j := 1; j <= w; j++{
			b = append(b, &Pos{i, j})
		}
		beams = append(beams, b)
	}
	for j := 1; j <= w; j++ {
		b := []*Pos{}
		for i := 1; i <= h; i++ {
			b = append(b, &Pos{i, j})
		}
		beams = append(beams, b)
	}
	for i := 1; i <= h; i++ {
		b := []*Pos{}
		for j := 1; j <= w&& i+j-1 <= h; j++ {
			b = append(b, &Pos{ i+j-1, j})
		}
		beams = append(beams, b)
	}
	for i := 1; i <= h; i++ {
		b := []*Pos{}
		for j := 1; j <= w && i-j+1 >= 1; j++ {
			b = append(b, &Pos{ i-j+1, j})
		}
		beams = append(beams, b)
	}
	for j := 1; j <= w; j++ {
		b := []*Pos{}
		for i := 1; i <= h && j+i-1 <= w; i++ {
			b = append(b, &Pos{ i, j+i-1 })
		}
		beams = append(beams, b)
	}
	for j := 1; j <= w; j++ {
		b := []*Pos{}
		for i := h; i >= 1 && j+h-i <= w; i-- {
			b = append(b, &Pos{ i, j+h-i })
		}
		beams = append(beams, b)
	}
	var ans int
	for i, beam1 := range beams {
		score1 := 0
		broken := map[int]bool{}
		for _, p := range beam1 {
			score1 += grid[p.row][p.col]
			broken[p.row*(w+2)+p.col] = true
		}
		for _, beam2 := range beams[i+1:] {
			score := score1
			for _, p := range beam2 {
				if !broken[p.row*(w+2)+p.col] {
					score += grid[p.row][p.col]
				}
			}
			ans = max(ans, score)
		}
	}
	Println(ans)
}
0