結果
問題 | No.1265 Balloon Survival |
ユーザー | ccppjsrb |
提出日時 | 2020-10-23 22:27:01 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 169 ms / 2,000 ms |
コード長 | 2,323 bytes |
コンパイル時間 | 11,680 ms |
コンパイル使用メモリ | 222,944 KB |
実行使用メモリ | 13,568 KB |
最終ジャッジ日時 | 2024-07-21 11:11:00 |
合計ジャッジ時間 | 14,878 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
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) cc := make([]circle, n) for i := 0; i < n; i++ { cc[i].x = getNextInt(scanner) cc[i].y = getNextInt(scanner) } dd := make([][3]int, 0, n*n) for i := 0; i < n; i++ { for j := 0; j < i; j++ { dd = append(dd, [3]int{i, j, dist(cc[i], cc[j])}) } } removed := make([]bool, n) broken := make([]bool, n) sort.Slice(dd, func(i, j int) bool { return dd[i][2] < dd[j][2] }) for i := 0; i < len(dd); i++ { if dd[i][0] == 0 { if removed[dd[i][1]] || broken[dd[i][1]] { continue } removed[dd[i][1]] = true continue } if dd[i][1] == 0 { if removed[dd[i][0]] || broken[dd[i][0]] { continue } removed[dd[i][0]] = true continue } if broken[dd[i][0]] || broken[dd[i][1]] { continue } if removed[dd[i][0]] || removed[dd[i][1]] { continue } broken[dd[i][0]] = true broken[dd[i][1]] = true } var ans int for i := 0; i < n; i++ { if removed[i] { ans++ } } fmt.Fprintln(writer, ans) } type circle struct { x, y int } func dist(a, b circle) int { return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) }