結果
問題 | No.949 飲酒プログラミングコンテスト |
ユーザー | ccppjsrb |
提出日時 | 2020-06-04 11:22:55 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 518 ms / 2,500 ms |
コード長 | 2,702 bytes |
コンパイル時間 | 12,877 ms |
コンパイル使用メモリ | 202,200 KB |
実行使用メモリ | 158,052 KB |
最終ジャッジ日時 | 2023-08-18 22:26:38 |
合計ジャッジ時間 | 21,013 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge10 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,384 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 2 ms
5,488 KB |
testcase_08 | AC | 5 ms
7,804 KB |
testcase_09 | AC | 3 ms
5,504 KB |
testcase_10 | AC | 4 ms
5,520 KB |
testcase_11 | AC | 262 ms
106,032 KB |
testcase_12 | AC | 328 ms
158,052 KB |
testcase_13 | AC | 241 ms
95,612 KB |
testcase_14 | AC | 37 ms
22,720 KB |
testcase_15 | AC | 210 ms
74,784 KB |
testcase_16 | AC | 417 ms
135,168 KB |
testcase_17 | AC | 57 ms
28,740 KB |
testcase_18 | AC | 496 ms
141,428 KB |
testcase_19 | AC | 256 ms
106,040 KB |
testcase_20 | AC | 59 ms
35,204 KB |
testcase_21 | AC | 17 ms
18,540 KB |
testcase_22 | AC | 36 ms
30,860 KB |
testcase_23 | AC | 4 ms
7,956 KB |
testcase_24 | AC | 239 ms
78,960 KB |
testcase_25 | AC | 418 ms
147,680 KB |
testcase_26 | AC | 456 ms
147,676 KB |
testcase_27 | AC | 469 ms
147,676 KB |
testcase_28 | AC | 518 ms
147,680 KB |
testcase_29 | AC | 357 ms
147,676 KB |
testcase_30 | AC | 265 ms
147,680 KB |
testcase_31 | AC | 234 ms
147,676 KB |
testcase_32 | AC | 433 ms
147,676 KB |
ソースコード
package main import ( "bufio" "fmt" "math" "os" "sort" "strconv" ) func getScanner(fp *os.File) *bufio.Scanner { scanner := bufio.NewScanner(fp) scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) return scanner } func getNextString(scanner *bufio.Scanner) string { scanner.Scan() 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 getNextUint64(scanner *bufio.Scanner) uint64 { i, _ := strconv.ParseUint(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 cnt := 0 if os.Getenv("MASPY") == "ますピ" { fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT")) cnt = 4 } if os.Getenv("MASPYPY") == "ますピッピ" { wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10")) } scanner := getScanner(fp) writer := bufio.NewWriter(wfp) solve(scanner, writer) for i := 0; i < cnt; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } writer.Flush() } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) aa := make([]int, n+1) bb := make([]int, n+1) dd := make([]int, n) for i := 0; i < n+1; i++ { aa[i] = getNextInt(scanner) } for i := 0; i < n+1; i++ { bb[i] = getNextInt(scanner) } for i := 0; i < n; i++ { dd[i] = getNextInt(scanner) } sort.Ints(dd) l := 0 r := n + 1 for 1 < r-l { m := l + (r-l)>>1 if ok(n, m, dd[:m], aa, bb) { l = m continue } r = m } fmt.Fprintln(writer, l) } type cint int func (x *cint) min(y cint) *cint { if *x > y { *x = y } return x } func (x *cint) max(y cint) *cint { if *x < y { *x = y } return x } func makeGrid(h, w int) [][]int { index := make([][]int, h, h) data := make([]int, h*w, h*w) for i := 0; i < h; i++ { index[i] = data[i*w : (i+1)*w] } return index } func ok(n, m int, dd, aa, bb []int) bool { dp := makeGrid(n+1, n+1) for i := 0; i < n+1; i++ { for j := 0; j < n+1; j++ { dp[i][j] = -math.MaxInt32 } } dp[0][0] = aa[0] + bb[0] for i := 0; i < m; i++ { for j := 0; j <= i; j++ { if dp[i][j] == -math.MaxInt32 { continue } if aa[j]+bb[i+1-j] >= dd[m-1-i] { dp[i+1][j] = aa[j] + bb[i+1-j] } if aa[j+1]+bb[i-j] >= dd[m-1-i] { dp[i+1][j+1] = aa[j+1] + bb[i-j] } } } for i := 0; i <= m; i++ { if dp[m][i] != -math.MaxInt32 { return true } } return false }