結果

問題 No.710 チーム戦
ユーザー ccppjsrbccppjsrb
提出日時 2020-06-06 19:45:40
言語 Go
(1.22.1)
結果
AC  
実行時間 21 ms / 3,000 ms
コード長 2,682 bytes
コンパイル時間 13,027 ms
コンパイル使用メモリ 200,572 KB
実行使用メモリ 5,476 KB
最終ジャッジ日時 2023-08-25 01:48:44
合計ジャッジ時間 14,865 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	bb := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
		bb[i] = getNextInt(scanner)
	}
	lim := 100000
	dp := make([]cint, lim+1)
	for i := 0; i < lim; i++ {
		dp[i+1] = cint(math.MaxInt32)
	}
	for i := 0; i < n; i++ {
		for j := lim; j >= 0; j-- {
			if dp[j].sub(math.MaxInt32) != 0 {
				dp[j] = dp[j].add(bb[i])
			}
			if j-aa[i] < 0 {
				continue
			}
			if dp[j-aa[i]].sub(math.MaxInt32) != 0 {
				dp[j].minAs(dp[j-aa[i]])
			}
		}
	}
	var ans cint
	ans = dp[0]
	for i := 0; i < lim+1; i++ {
		ans.minAs(dp[i].max(i))
	}
	fmt.Fprintln(writer, ans)
}

type cint int

func (ct *cint) cintize(x interface{}) cint {
	if y, isCint := x.(cint); isCint {
		return y
	}
	if y, isInt64 := x.(int64); isInt64 {
		return cint(y)
	}
	return cint(x.(int))
}
func (ct *cint) minAs(x interface{}) *cint {
	*ct = ct.min(x)
	return ct
}
func (ct *cint) maxAs(x interface{}) *cint {
	*ct = ct.max(x)
	return ct
}
func (ct cint) min(x interface{}) cint {
	y := ct.cintize(x)
	if ct > y {
		return y
	}
	return ct
}
func (ct cint) max(x interface{}) cint {
	y := ct.cintize(x)
	if ct < y {
		return y
	}
	return ct
}
func (ct cint) add(x interface{}) cint {
	return ct + ct.cintize(x)
}
func (ct cint) sub(x interface{}) cint {
	return ct - ct.cintize(x)
}
func (ct cint) mul(x interface{}) cint {
	return ct * ct.cintize(x)
}
func (ct cint) div(x interface{}) cint {
	return ct / ct.cintize(x)
}
0