結果
問題 | No.393 2本の竹 |
ユーザー | aru aru |
提出日時 | 2020-10-18 11:55:29 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 277 ms / 1,000 ms |
コード長 | 2,031 bytes |
コンパイル時間 | 13,263 ms |
コンパイル使用メモリ | 215,872 KB |
実行使用メモリ | 101,848 KB |
最終ジャッジ日時 | 2023-09-28 08:53:28 |
合計ジャッジ時間 | 16,579 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 198 ms
99,784 KB |
testcase_01 | AC | 191 ms
101,684 KB |
testcase_02 | AC | 189 ms
101,680 KB |
testcase_03 | AC | 189 ms
101,684 KB |
testcase_04 | AC | 192 ms
101,620 KB |
testcase_05 | AC | 182 ms
101,760 KB |
testcase_06 | AC | 182 ms
101,616 KB |
testcase_07 | AC | 189 ms
99,712 KB |
testcase_08 | AC | 196 ms
101,796 KB |
testcase_09 | AC | 277 ms
101,848 KB |
testcase_10 | AC | 215 ms
101,748 KB |
testcase_11 | AC | 228 ms
101,684 KB |
testcase_12 | AC | 228 ms
99,776 KB |
testcase_13 | AC | 215 ms
101,788 KB |
testcase_14 | AC | 209 ms
99,676 KB |
testcase_15 | AC | 49 ms
101,588 KB |
testcase_16 | AC | 147 ms
101,680 KB |
testcase_17 | AC | 190 ms
101,720 KB |
testcase_18 | AC | 198 ms
99,764 KB |
testcase_19 | AC | 135 ms
101,696 KB |
testcase_20 | AC | 189 ms
99,688 KB |
testcase_21 | AC | 191 ms
101,692 KB |
testcase_22 | AC | 239 ms
99,784 KB |
testcase_23 | AC | 210 ms
101,748 KB |
testcase_24 | AC | 205 ms
99,700 KB |
testcase_25 | AC | 183 ms
99,748 KB |
testcase_26 | AC | 154 ms
101,688 KB |
testcase_27 | AC | 254 ms
101,764 KB |
ソースコード
package main import ( "bufio" "fmt" "os" "sort" "strconv" ) var sc = bufio.NewScanner(os.Stdin) var wr = bufio.NewWriter(os.Stdout) func out(x ...interface{}) { fmt.Fprintln(wr, x...) } func getI() int { sc.Scan() i, e := strconv.Atoi(sc.Text()) if e != nil { panic(e) } return i } func getF() float64 { sc.Scan() i, e := strconv.ParseFloat(sc.Text(), 64) if e != nil { panic(e) } return i } func getInts(N int) []int { ret := make([]int, N) for i := 0; i < N; i++ { ret[i] = getI() } return ret } func getS() string { sc.Scan() return sc.Text() } // min, max, asub, absなど基本関数 func max(a, b int) int { if a > b { return a } return b } func min(a, b int) int { if a < b { return a } return b } func asub(a, b int) int { if a > b { return a - b } return b - a } func abs(a int) int { if a >= 0 { return a } return -a } func lowerBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] >= x }) return idx } func upperBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] > x }) return idx } func f() { n1, n2 := getI(), getI() m := getI() a := getInts(m) sort.Ints(a) a = append([]int{0}, a...) sum := n1 + n2 s := make([]int, m+1) s[0] = 0 for i := 0; i < m; i++ { s[i+1] += s[i] + a[i+1] } var dp [61][100100]int for i := 0; i < 61; i++ { for j := 0; j < 100100; j++ { dp[i][j] = -1 } } dp[0][n1] = 0 for i := 0; i < m; i++ { for j := 0; j <= n1; j++ { if j-a[i+1] >= 0 && dp[i][j] != -1 { dp[i+1][j-a[i+1]] = dp[i][j] + 1 } if sum-j-s[i] >= a[i+1] && dp[i][j] != -1 { dp[i+1][j] = dp[i][j] + 1 } } } ans := -100 for i := 0; i < 61; i++ { for j := 0; j < 100100; j++ { ans = max(ans, dp[i][j]) } } out(ans) } func main() { defer wr.Flush() sc.Split(bufio.ScanWords) sc.Buffer([]byte{}, 1000000) // this template is new version. // use getI(), getS(), getInts(), getF() d := getI() for i := 0; i < d; i++ { f() } }