結果

問題 No.94 圏外です。(EASY)
ユーザー fmhrfmhr
提出日時 2016-07-25 14:04:10
言語 Go
(1.22.1)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,917 bytes
コンパイル時間 14,127 ms
コンパイル使用メモリ 218,008 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-08 14:55:49
合計ジャッジ時間 12,262 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 6 ms
4,388 KB
testcase_08 AC 12 ms
4,376 KB
testcase_09 AC 19 ms
4,380 KB
testcase_10 AC 19 ms
4,380 KB
testcase_11 AC 19 ms
4,384 KB
testcase_12 AC 19 ms
4,384 KB
testcase_13 AC 19 ms
4,376 KB
testcase_14 AC 19 ms
4,380 KB
testcase_15 AC 19 ms
4,376 KB
testcase_16 AC 19 ms
4,376 KB
testcase_17 AC 18 ms
4,380 KB
testcase_18 AC 19 ms
4,380 KB
testcase_19 AC 19 ms
4,376 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

type xy struct {
	x int
	y int
}

func isLink(a, b, c, d int) bool {
	return 100 >= (c-a)*(c-a)+(d-b)*(d-b)
}

func distance(a, b, c, d int) float64 {
	x := math.Sqrt(float64((c-a)*(c-a) + (b-d)*(b-d)))
	return x
}

func main() {
	sc.Split(bufio.ScanWords)

	var N int
	//fmt.Scan(&N)
	N = nextInt()
	repeater := make([]xy, N)
	for i := 0; i < N; i++ {
		//fmt.Scan(&repeater[i].x, &repeater[i].y)
		repeater[i].x = nextInt()
		repeater[i].y = nextInt()
	}
	uf := NewUnionFind(N)
	for i := 0; i < N; i++ {
		for j := i; j < N; j++ {
			if isLink(repeater[i].x, repeater[i].y, repeater[j].x, repeater[j].y) {
				uf.Unit(i, j)
			}
		}
	}
	ans := 1.0
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if uf.Same(i, j) {
				ans = max(ans, 2+distance(repeater[i].x, repeater[i].y, repeater[j].x, repeater[j].y))
			}
		}
	}
	fmt.Println(ans)
}

func max(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

type UnionFind struct {
	par    []int // 親
	weight []int // 重み
}

func NewUnionFind(count int) *UnionFind {
	par := make([]int, count)
	weight := make([]int, count)
	for i := 0; i < count; i++ {
		par[i] = i
		weight[i] = 1
	}
	return &UnionFind{par: par, weight: weight}
}

func (uf *UnionFind) Find(x int) int {
	if uf.par[x] == x {
		return x
	} else {
		uf.par[x] = uf.par[uf.par[x]]
		return uf.Find(uf.par[x])
	}
}

func (uf *UnionFind) Unit(x, y int) {
	x = uf.Find(x)
	y = uf.Find(y)
	if x == y {
		return
	}
	if uf.weight[x] > uf.weight[y] {
		x, y = y, x
	}
	uf.par[x] = y
	uf.weight[y] += uf.weight[x]
}

func (uf *UnionFind) Same(x, y int) bool {
	return uf.Find(x) == uf.Find(y)
}

func (uf UnionFind) test() {
	fmt.Println(uf.weight)
}

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}
0