結果
問題 | No.286 Modulo Discount Store |
ユーザー | yuki2006 |
提出日時 | 2015-07-09 20:24:54 |
言語 | Go1.4 (1.4.2) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,400 bytes |
コンパイル時間 | 375 ms |
コンパイル使用メモリ | 33,860 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-05-03 20:22:24 |
合計ジャッジ時間 | 4,012 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
10,624 KB |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | TLE | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
ソースコード
package main import ( "fmt" ) import ( "bufio" "os" "strconv" "sort" ) func main() { N := nextInt() var data = make([]int, N) for i := 0; i < N; i++ { data[i] = nextInt() } sort.Ints(data) minBuyTotal := N * 10000 for { buy := 0 priceTotal := 0 for i := 0; i < N; i++ { buy+=data[i]-min(data[i], priceTotal%1000) priceTotal+=data[i] } minBuyTotal = min(minBuyTotal, buy) if !next_permutation(data) { break } } fmt.Println(minBuyTotal) } func next_permutation(a []int) bool { for i := len(a) - 2; i >= 0; i-- { if a[i] < a[i+1] { for j := len(a) - 1; j >= 0; j-- { if a[j] >= a[i] { a[i], a[j] = a[j], a[i] reverse(a, i+1, len(a)-(i+1)) return true } } } } reverse(a, 0, len(a)) return false } 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-- } } var s = bufio.NewScanner(os.Stdin) func min(a int, b int) int { if a < b { return a } return b } func next() string { s.Split(bufio.ScanWords) s.Scan() return s.Text() } func nextLine() string { s.Split(bufio.ScanLines) s.Scan() return s.Text() } func nextInt() int { i, e := strconv.Atoi(next()) if e != nil { panic(e) } return i } func nextLong() int64 { i, e := strconv.ParseInt(next(), 10, 64) if e != nil { panic(e) } return i }