結果

問題 No.135 とりあえず1次元の問題
ユーザー tyochiaityochiai
提出日時 2015-01-30 02:48:25
言語 Go
(1.22.1)
結果
AC  
実行時間 843 ms / 5,000 ms
コード長 557 bytes
コンパイル時間 11,500 ms
コンパイル使用メモリ 214,020 KB
実行使用メモリ 7,940 KB
最終ジャッジ日時 2023-08-31 01:33:22
合計ジャッジ時間 16,405 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 751 ms
7,932 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 7 ms
4,384 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 7 ms
4,376 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 843 ms
7,940 KB
testcase_22 AC 758 ms
7,940 KB
evil01.txt AC 759 ms
7,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"math"
	"sort"
)

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func resolve(N int, X []int) int {
	ret := 1000001
	sort.Ints(X)
	for i := 0; i < N-1; i++ {
		if X[i] == X[i+1] {
			continue
		}
		ret = min(ret, abs(X[i]-X[i+1]))
	}
	if ret == 1000001 {
		return 0
	}
	return ret
}

func main() {
	var N int

	fmt.Scanf("%d\n", &N)

	X := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &X[i])
	}

	fmt.Println(resolve(N, X))
}
0