結果

問題 No.1265 Balloon Survival
ユーザー 小野寺健小野寺健
提出日時 2021-12-20 10:17:18
言語 Go
(1.22.1)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 11,153 ms
コンパイル使用メモリ 210,056 KB
実行使用メモリ 16,212 KB
最終ジャッジ日時 2023-10-13 19:28:20
合計ジャッジ時間 15,119 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,356 KB
testcase_03 AC 2 ms
4,356 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,356 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 19 ms
4,352 KB
testcase_15 AC 14 ms
4,352 KB
testcase_16 AC 6 ms
4,372 KB
testcase_17 AC 86 ms
9,972 KB
testcase_18 AC 8 ms
4,352 KB
testcase_19 AC 6 ms
4,352 KB
testcase_20 AC 19 ms
4,348 KB
testcase_21 AC 42 ms
5,596 KB
testcase_22 AC 25 ms
5,568 KB
testcase_23 AC 28 ms
5,576 KB
testcase_24 AC 165 ms
16,208 KB
testcase_25 AC 164 ms
16,212 KB
testcase_26 AC 166 ms
16,208 KB
testcase_27 AC 165 ms
16,212 KB
testcase_28 AC 163 ms
16,212 KB
testcase_29 AC 168 ms
16,208 KB
testcase_30 AC 165 ms
16,208 KB
testcase_31 AC 167 ms
16,208 KB
testcase_32 AC 166 ms
16,212 KB
testcase_33 AC 166 ms
16,212 KB
testcase_34 AC 1 ms
4,352 KB
testcase_35 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"bufio"
	"os"
	"sort"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	xy := make([][2]int, n)
	for i := 0; i < n; i++ {
		var x, y int
		fmt.Fscan(r, &x, &y)
		xy[i] = [2]int{x, y}
	}
	dist := make([][3]int, n * (n-1) / 2)
	k := 0
	for i := 0; i < n; i++ {
		xi, yi := xy[i][0], xy[i][1]
		for j := i+1; j < n; j++ {
			xj, yj := xy[j][0], xy[j][1]
			d := (xi - xj) * (xi - xj) + (yi - yj) * (yi - yj)
			dist[k] = [3]int{d, i, j}
			k++
		}
	}
	sort.Slice(dist, func(i, j int) bool {return dist[i][0] < dist[j][0]})
	dead := make([]bool, n)
	alive_n := n
	remove := 0
	for _, x := range dist {
		i, j := x[1], x[2]
		if i == 0 && !dead[j] {
			remove++
			dead[j] = true
			alive_n--
		} else if !dead[i] && !dead[j] {
			dead[i] = true
			dead[j] = true
		}
		if alive_n == 1 {
			break
		}
	}
	fmt.Fprintln(w, remove)
}
0