結果

問題 No.370 道路の掃除
ユーザー yuki2006yuki2006
提出日時 2016-05-11 00:17:28
言語 Go
(1.22.1)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 14,520 ms
コンパイル使用メモリ 212,776 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-04 19:25:07
合計ジャッジ時間 15,938 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 7 ms
4,376 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 5 ms
4,376 KB
testcase_29 AC 6 ms
4,376 KB
testcase_30 AC 7 ms
4,376 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 6 ms
4,508 KB
testcase_33 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"sort"
)

func reverse(a []int, start int, length int) {
	var end = start + length - 1
	for start < end {
		a[start], a[end] = a[end], a[start]
		start++
		end--
	}
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var N, M int

	fmt.Scanf("%d %d", &N, &M)

	// 0個取るというのを0番目が0というので表現する
	Minus := make([]int, 1)
	Plus := make([]int, 1)

	for i := 0; i < M; i++ {
		var T int
		fmt.Scanf("%d", &T)
		if T < 0 {
			Minus = append(Minus, -T)
		} else {
			Plus = append(Plus, T)
		}
	}
	sort.Ints(Minus)
	sort.Ints(Plus)
        // 値の最大値
	ans := 30000

	for i := 0; i <= N; i++ {
		// i個 正の方向から取る
		a := ans
		b := ans
		if i < len(Plus) && N - i < len(Minus) {
			a = Plus[i] + Minus[N - i] * 2
		}
		if N - i < len(Plus) && i < len(Minus) {
			b = Plus[N - i] * 2 + Minus[i]
		}
		v := min(a, b)
		ans = min(ans, v)
	}
	fmt.Println(ans)

}
0