結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー ccppjsrbccppjsrb
提出日時 2020-06-04 11:15:25
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 2,707 bytes
コンパイル時間 11,876 ms
コンパイル使用メモリ 211,844 KB
実行使用メモリ 218,436 KB
最終ジャッジ日時 2023-08-18 22:04:15
合計ジャッジ時間 19,951 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 2 ms
5,488 KB
testcase_08 WA -
testcase_09 AC 2 ms
5,504 KB
testcase_10 AC 3 ms
5,520 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 207 ms
74,788 KB
testcase_16 AC 414 ms
135,168 KB
testcase_17 AC 51 ms
37,096 KB
testcase_18 AC 465 ms
141,428 KB
testcase_19 AC 247 ms
106,040 KB
testcase_20 AC 52 ms
35,236 KB
testcase_21 AC 15 ms
18,544 KB
testcase_22 AC 31 ms
30,852 KB
testcase_23 AC 4 ms
7,956 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 453 ms
147,680 KB
testcase_27 AC 459 ms
147,680 KB
testcase_28 AC 515 ms
147,676 KB
testcase_29 AC 353 ms
147,680 KB
testcase_30 AC 322 ms
218,436 KB
testcase_31 AC 253 ms
147,676 KB
testcase_32 AC 426 ms
147,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = 3
	}
	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 := -1
	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+1; 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[i+1-j]+bb[j] >= dd[m-1-i] {
				dp[i+1][i+1-j] = aa[i+1-j] + bb[j]
			}
		}
	}
	for i := 0; i <= m; i++ {
		if dp[m][i] != -math.MaxInt32 {
			return true
		}
	}

	return false
}
0