結果
問題 | No.771 しおり |
ユーザー | ccppjsrb |
提出日時 | 2020-08-27 21:35:12 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 283 ms / 2,000 ms |
コード長 | 2,249 bytes |
コンパイル時間 | 11,197 ms |
コンパイル使用メモリ | 240,508 KB |
実行使用メモリ | 46,648 KB |
最終ジャッジ日時 | 2024-07-22 07:24:15 |
合計ジャッジ時間 | 15,722 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 282 ms
46,648 KB |
testcase_01 | AC | 28 ms
7,628 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 1 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 1 ms
6,944 KB |
testcase_18 | AC | 1 ms
6,948 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 1 ms
6,940 KB |
testcase_21 | AC | 1 ms
6,940 KB |
testcase_22 | AC | 1 ms
6,944 KB |
testcase_23 | AC | 1 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 129 ms
24,096 KB |
testcase_26 | AC | 3 ms
6,940 KB |
testcase_27 | AC | 27 ms
7,632 KB |
testcase_28 | AC | 58 ms
13,780 KB |
testcase_29 | AC | 28 ms
7,628 KB |
testcase_30 | AC | 282 ms
46,644 KB |
testcase_31 | AC | 278 ms
46,644 KB |
testcase_32 | AC | 6 ms
6,940 KB |
testcase_33 | AC | 279 ms
46,644 KB |
testcase_34 | AC | 283 ms
46,644 KB |
testcase_35 | AC | 6 ms
6,944 KB |
testcase_36 | AC | 2 ms
6,944 KB |
testcase_37 | AC | 3 ms
6,940 KB |
testcase_38 | AC | 7 ms
6,940 KB |
testcase_39 | AC | 3 ms
6,944 KB |
testcase_40 | AC | 127 ms
24,096 KB |
testcase_41 | AC | 279 ms
46,648 KB |
testcase_42 | AC | 281 ms
46,644 KB |
testcase_43 | AC | 28 ms
7,632 KB |
testcase_44 | AC | 283 ms
46,648 KB |
testcase_45 | AC | 281 ms
46,648 KB |
ソースコード
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) } size := 1 << uint(n) dp := makeGrid(size, n) for i := 0; i < size; i++ { for j := 0; j < n; j++ { if i == 1<<uint(j) { continue } dp[i][j] = math.MaxInt32 } } for i := 1; i < size; i++ { for j := 0; j < n; j++ { if i>>uint(j)&1 == 0 { continue } for k := 0; k < n; k++ { if i>>uint(k)&1 == 1 { continue } dp[i|(1<<uint(k))][k] = min(dp[i|(1<<uint(k))][k], max(dp[i][j], bb[j]-aa[j]+aa[k])) } } } var ans int ans = dp[size-1][0] for i := 1; i < n; i++ { ans = min(ans, dp[size-1][i]) } fmt.Fprintln(writer, ans) } func max(a, b int) int { if a < b { return b } return a } func min(a, b int) int { return -max(-a, -b) } 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 }