結果
問題 | No.165 四角で囲え! |
ユーザー | ccppjsrb |
提出日時 | 2020-06-13 16:54:01 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 241 ms / 5,000 ms |
コード長 | 2,954 bytes |
コンパイル時間 | 14,086 ms |
コンパイル使用メモリ | 238,324 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 14:49:36 |
合計ジャッジ時間 | 16,768 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 94 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 132 ms
5,376 KB |
testcase_06 | AC | 32 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 57 ms
5,376 KB |
testcase_12 | AC | 23 ms
5,376 KB |
testcase_13 | AC | 24 ms
5,376 KB |
testcase_14 | AC | 18 ms
5,376 KB |
testcase_15 | AC | 17 ms
5,376 KB |
testcase_16 | AC | 188 ms
5,376 KB |
testcase_17 | AC | 143 ms
5,376 KB |
testcase_18 | AC | 241 ms
5,376 KB |
testcase_19 | AC | 166 ms
5,376 KB |
testcase_20 | AC | 145 ms
5,376 KB |
testcase_21 | AC | 144 ms
5,376 KB |
testcase_22 | AC | 144 ms
5,376 KB |
ソースコード
package main import ( "bufio" "fmt" "os" "sort" "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) b := getNextInt(scanner) xx := make([]int, n) yy := make([]int, n) pp := make([]int, n) for i := 0; i < n; i++ { xx[i] = getNextInt(scanner) yy[i] = getNextInt(scanner) pp[i] = getNextInt(scanner) } xm := rankmap(xx) ym := rankmap(yy) xl := len(xm) yl := len(ym) g := makeGrid(yl+1, xl+1) c := makeGrid(yl+1, xl+1) for i := 0; i < n; i++ { g[ym[yy[i]]][xm[xx[i]]] = pp[i] c[ym[yy[i]]][xm[xx[i]]] = 1 } for y := 0; y < yl+1; y++ { for x := 1; x < xl+1; x++ { g[y][x] += g[y][x-1] c[y][x] += c[y][x-1] } } for x := 0; x < xl+1; x++ { for y := 1; y < yl+1; y++ { g[y][x] += g[y-1][x] c[y][x] += c[y-1][x] } } var ans cint for ty := 0; ty < yl+1; ty++ { for sy := 0; sy < ty; sy++ { l := -1 for r := 1; r < xl+1; r++ { for r > l && g[ty][r]-g[ty][l+1]-g[sy][r]+g[sy][l+1] > b { l++ } ans.maxAs(cint(c[ty][r] - c[ty][l+1] - c[sy][r] + c[sy][l+1])) } } } 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 rankmap(xx []int) map[int]int { m := map[int]int{} for _, x := range xx { m[x] = 1 } yy := make([]int, 0) for x := range m { yy = append(yy, x) } sort.Ints(yy) ret := map[int]int{} for i := 0; i < len(yy); i++ { ret[yy[i]] = i + 1 } return ret } type cint int64 func (ct *cint) minAs(x cint) *cint { *ct = ct.min(x) return ct } func (ct *cint) maxAs(x cint) *cint { *ct = ct.max(x) return ct } func (ct cint) min(x cint) cint { if ct > x { return x } return ct } func (ct cint) max(x cint) cint { if ct < x { return x } return ct }