結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2020-08-30 21:00:35 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 1,090 ms / 2,000 ms |
コード長 | 2,673 bytes |
コンパイル時間 | 12,709 ms |
コンパイル使用メモリ | 221,768 KB |
実行使用メモリ | 36,340 KB |
最終ジャッジ日時 | 2024-11-15 15:25:57 |
合計ジャッジ時間 | 17,915 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
package mainimport ("bufio""fmt""os""sort""strconv")func out(x ...interface{}) {fmt.Println(x...)}var sc = bufio.NewScanner(os.Stdin)func getInt() int {sc.Scan()i, e := strconv.Atoi(sc.Text())if e != nil {panic(e)}return i}func getInts(N int) []int {ret := make([]int, N)for i := 0; i < N; i++ {ret[i] = getInt()}return ret}func getString() string {sc.Scan()return sc.Text()}// min, max, asub, absなど基本関数func max(a, b int) int {if a > b {return a}return b}func min(a, b int) int {if a < b {return a}return b}func asub(a, b int) int {if a > b {return a - b}return b - a}func abs(a int) int {if a >= 0 {return a}return -a}func lowerBound(a []int, x int) int {idx := sort.Search(len(a), func(i int) bool {return a[i] >= x})return idx}func upperBound(a []int, x int) int {idx := sort.Search(len(a), func(i int) bool {return a[i] > x})return idx}type dist struct {l, x, y int}func lowerBoundDist(a []dist, x int) int {idx := sort.Search(len(a), func(i int) bool {return a[i].l >= x})return idx}func upperBoundDist(a []dist, x int) int {idx := sort.Search(len(a), func(i int) bool {return a[i].l > x})return idx}type unionfind []intfunc newUionfind(n int) unionfind {ret := make(unionfind, n)for i := 0; i < n; i++ {ret[i] = -1}return ret}func (u unionfind) r(x int) int {if u[x] < 0 {return x}root := u.r(u[x])return root}func (u unionfind) unite(i, j int) {x := u.r(i)y := u.r(j)if x == y {return}u[x] += u[y]u[y] = x}func (u unionfind) same(i, j int) bool {x := u.r(i)y := u.r(j)if x == y {return true}return false}func (u unionfind) size(i int) int {x := u.r(i)return -u[x]}func main() {sc.Split(bufio.ScanWords)N := getInt()x := make([]int, N)y := make([]int, N)for i := 0; i < N; i++ {x[i], y[i] = getInt(), getInt()}d := make([]dist, 0)for i := 0; i < N; i++ {for j := i + 1; j < N; j++ {dx := abs(x[i] - x[j])dy := abs(y[i] - y[j])d = append(d, dist{dx*dx + dy*dy, i, j})}}sort.Slice(d, func(i, j int) bool {return d[i].l < d[j].l})// out(d)// xx := min(len(d)-1, upperBoundDist(d, 0))// out(d[xx])l := 0r := 1500000000for l+1 != r {m := (l + r) / 2uf := newUionfind(N)// p := upperBoundDist(d, m)// for i := 0; i < p; i++ {// uf.unite(d[i].x, d[i].y)// }for _, e := range d {if e.l <= m*m {// out(e, m)uf.unite(e.x, e.y)}}if uf.same(0, N-1) {r = m} else {l = m}}// out(r)out(((r + 9) / 10) * 10)}