結果

問題 No.29 パワーアップ
ユーザー deruiderui
提出日時 2016-02-15 23:20:29
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,000 bytes
コンパイル時間 12,449 ms
コンパイル使用メモリ 228,840 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 05:34:16
合計ジャッジ時間 12,765 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main
import "fmt"
import "bufio"
import "os"

func loadItems(numOfDefeats int, sc *bufio.Scanner) []int {
	// 0-9で表す。
	items := make([]int, 10)

	for i := 0;i < numOfDefeats; i++ {
		var r1, r2, r3 int
		sc.Scan()

		text := sc.Text()
		fmt.Sscanf(text, "%d %d %d", &r1, &r2, &r3)
		for _, v := range []int{r1, r2, r3} {
			items[v - 1]++
		}
	}

	return items
}

func main() {
	var defeats int
	fmt.Scan(&defeats)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)
	items := loadItems(defeats, sc)

	fmt.Println(solve(items))
}

func solve(defeats []int) int {
	result := 0

	// それぞれのアイテムについて、2で割った商だけパワーアップできる。
	for ind, v := range defeats {
		quotient := v / 2
		rem := v % 2
		result += quotient
		defeats[ind] = rem
	}

	// 残ったアイテムの個数を4で割った商の回数だけパワーアップできる
	sum := 0
	for _, v := range defeats {
		sum += v
	}
	result += sum / 4

	return result
}
0