結果

問題 No.617 Nafmo、買い出しに行く
ユーザー motimoti
提出日時 2018-05-20 15:39:59
言語 Go
(1.22.1)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 807 bytes
コンパイル時間 12,413 ms
コンパイル使用メモリ 200,748 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 00:02:57
合計ジャッジ時間 15,166 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 13 ms
4,376 KB
testcase_06 AC 103 ms
4,376 KB
testcase_07 AC 103 ms
4,376 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 102 ms
4,380 KB
testcase_11 AC 102 ms
4,380 KB
testcase_12 AC 102 ms
4,380 KB
testcase_13 AC 99 ms
4,380 KB
testcase_14 AC 103 ms
4,376 KB
testcase_15 AC 96 ms
4,380 KB
testcase_16 AC 96 ms
4,380 KB
testcase_17 AC 96 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	cols := strings.Split(nextLine(), " ")
	n, err := strconv.Atoi(cols[0])
	if err != nil {
		log.Fatal(err)
	}
	k, err := strconv.Atoi(cols[1])
	if err != nil {
		log.Fatal(err)
	}
	var a []int
	for i := 0; i < n; i++ {
		m := nextInt()
		a = append(a, m)
	}
	ma := 0
	for s := 0; s < (1 << uint(n)); s++ {
		count := 0
		for i := 0; i < n; i++ {
			if (s & (1 << uint(i))) > 0 {
				count += a[i]
			}
		}
		if count <= k {
			ma = int(math.Max(float64(ma), float64(count)))
		}
	}
	fmt.Println(ma)
}
0