結果

問題 No.370 道路の掃除
ユーザー tsuchinagatsuchinaga
提出日時 2019-04-11 12:10:54
言語 Go
(1.22.1)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 12,205 ms
コンパイル使用メモリ 215,840 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 12:29:07
合計ジャッジ時間 12,144 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 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,380 KB
testcase_14 AC 2 ms
4,376 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,380 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 6 ms
4,376 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 6 ms
4,380 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 6 ms
4,380 KB
testcase_30 AC 7 ms
4,380 KB
testcase_31 AC 5 ms
4,376 KB
testcase_32 AC 6 ms
4,376 KB
testcase_33 AC 7 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func main() {
	var n, m int
	_, _ = fmt.Scan(&n, &m)

	d := 0
	pn := make([]int, 0)
	mn := make([]int, 0)
	for i := 0; i < m; i++ {
		_, _ = fmt.Scan(&d)
		if d == 0 {
			n--
		} else if d > 0 {
			pn = append(pn, d)
		} else {
			mn = append(mn, d*-1)
		}
	}

	sort.Slice(pn, func(i, j int) bool {
		return pn[i] < pn[j]
	})

	sort.Slice(mn, func(i, j int) bool {
		return mn[i] < mn[j]
	})

	// fmt.Println(pn)
	// fmt.Println(mn)

	min := -1
	for i := 0; i <= n; i++ {
		z := n

		var p, m int
		if i > 0 {
			j := int(math.Min(float64(i), float64(len(pn))))

			if j > 0 {
				p = pn[j-1]
				z -= j
			}
		}

		if z > 0 {
			j := int(math.Min(float64(z), float64(len(mn))))

			if j > 0 {
				m = mn[j-1]
				z -= j
			}
		}

		if z != 0 {
			continue
		}

		d := int(math.Min(float64(p), float64(m))) + p + m
		if min == -1 || min > d {
			min = d
		}
	}

	fmt.Println(min)
}
0