結果
問題 | No.1028 闇討ち |
ユーザー | ccppjsrb |
提出日時 | 2020-08-14 17:11:18 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 122 ms / 2,000 ms |
コード長 | 2,315 bytes |
コンパイル時間 | 11,322 ms |
コンパイル使用メモリ | 238,608 KB |
実行使用メモリ | 57,216 KB |
最終ジャッジ日時 | 2024-04-18 18:45:56 |
合計ジャッジ時間 | 14,404 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 6 ms
5,376 KB |
testcase_10 | AC | 8 ms
5,376 KB |
testcase_11 | AC | 26 ms
12,800 KB |
testcase_12 | AC | 113 ms
55,808 KB |
testcase_13 | AC | 109 ms
55,552 KB |
testcase_14 | AC | 59 ms
27,904 KB |
testcase_15 | AC | 21 ms
11,648 KB |
testcase_16 | AC | 115 ms
56,448 KB |
testcase_17 | AC | 122 ms
56,960 KB |
testcase_18 | AC | 116 ms
56,320 KB |
testcase_19 | AC | 115 ms
56,192 KB |
testcase_20 | AC | 116 ms
57,088 KB |
testcase_21 | AC | 122 ms
57,216 KB |
ソースコード
package main import ( "bufio" "fmt" "os" "strconv" ) func configure(scanner *bufio.Scanner) { scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) } func getNextString(scanner *bufio.Scanner) string { scanned := scanner.Scan() if !scanned { panic("scan failed") } return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout extra := 0 if os.Getenv("I") == "IronMan" { fp, _ = os.Open(os.Getenv("END_GAME")) extra = 100 } scanner := bufio.NewScanner(fp) configure(scanner) writer := bufio.NewWriter(wfp) defer func() { r := recover() if r != nil { fmt.Fprintln(writer, r) } writer.Flush() }() solve(scanner, writer) for i := 0; i < extra; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) aa := makeGrid(n, n) bb := make([][][2]int, n) var ans int for i := 0; i < n; i++ { for j := 0; j < n; j++ { aa[i][j] = getNextInt(scanner) - 1 bb[aa[i][j]] = append(bb[aa[i][j]], [2]int{i, j}) ans += j } } for i := 0; i < n; i++ { ll := make([]int, n) rr := make([]int, n) for j := 0; j < n; j++ { if bb[i][j][0]+bb[i][j][1]+1 >= n { continue } ll[bb[i][j][0]+bb[i][j][1]+1]++ } for j := 0; j < n; j++ { if bb[i][j][0]-bb[i][j][1]-1 < 0 { continue } rr[bb[i][j][0]-bb[i][j][1]-1]++ } for k := 0; k < 2; k++ { for j := 1; j < n; j++ { ll[j] += ll[j-1] } for j := n - 2; j >= 0; j-- { rr[j] += rr[j+1] } } mn := ll[0] + rr[0] for j := 1; j < n; j++ { if mn > ll[j]+rr[j] { mn = ll[j] + rr[j] } } ans += mn } fmt.Fprintln(writer, ans) } func makeGrid(h, w int) [][]int { index := make([][]int, h, h) data := make([]int, h*w, h*w) for i := 0; i < h; i++ { index[i] = data[i*w : (i+1)*w] } return index } func max(a, b int) int { if a < b { return b } return a }