結果

問題 No.135 とりあえず1次元の問題
ユーザー toshiro_yanagitoshiro_yanagi
提出日時 2022-06-05 20:19:18
言語 Go
(1.22.1)
結果
AC  
実行時間 848 ms / 5,000 ms
コード長 557 bytes
コンパイル時間 11,317 ms
コンパイル使用メモリ 211,932 KB
実行使用メモリ 9,520 KB
最終ジャッジ日時 2023-10-21 03:16:51
合計ジャッジ時間 17,461 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 796 ms
9,520 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 7 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 7 ms
4,348 KB
testcase_20 AC 6 ms
4,348 KB
testcase_21 AC 848 ms
7,880 KB
testcase_22 AC 793 ms
7,240 KB
evil01.txt AC 788 ms
9,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	var x []int
	maxsize := 0
	dic := map[int]struct{}{}

	fmt.Scan(&n)
	for range make([]struct{}, n) {
		var y int
		fmt.Scan(&y)
		if _, ok := dic[y]; !ok {
			maxsize = max(y, maxsize)
			x = append(x, y)
		}
		dic[y] = struct{}{}
	}
	sort.Ints(x)
	ans := maxsize
	for i := range make([]struct{}, len(x)-1) {
		ans = min(ans, x[i+1]-x[i])
	}
	fmt.Println(ans)
}

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
}
0