結果
問題 | No.1251 絶対に間違ってはいけない最小化問題 |
ユーザー | ccppjsrb |
提出日時 | 2020-10-09 22:00:43 |
言語 | Go (1.22.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,378 bytes |
コンパイル時間 | 15,605 ms |
コンパイル使用メモリ | 223,028 KB |
実行使用メモリ | 7,424 KB |
最終ジャッジ日時 | 2024-07-20 11:17:14 |
合計ジャッジ時間 | 28,696 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 94 ms
7,424 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 1 ms
5,376 KB |
testcase_44 | AC | 1 ms
5,376 KB |
ソースコード
package main import ( "bufio" "fmt" "os" "sort" "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) type pair [2]int pp := make([]pair, n) for i := 0; i < n; i++ { pp[i][0] = getNextInt(scanner) } for i := 0; i < n; i++ { pp[i][1] = getNextInt(scanner) } sort.Slice(pp, func(i, j int) bool { return pp[i][0] < pp[j][0] }) ss := make([]int64, n+1) for i := 0; i < n; i++ { ss[i+1] = ss[i] + int64(pp[i][1]) } l := -1 r := n + 1 for l+1 < r { m := (l + r) >> 1 if ss[m] < ss[n]-ss[m] { l = m continue } r = m } var ans int64 if r == 0 { x := pp[0][0] for i := 0; i < n; i++ { ans += int64(pp[i][1]) * int64(abs(x-pp[i][0])) } fmt.Fprintln(writer, fmt.Sprintf("%d %d", x, ans)) return } if r == n { x := pp[n-1][0] for i := 0; i < n; i++ { ans += int64(pp[i][1]) * int64(abs(x-pp[i][0])) } fmt.Fprintln(writer, fmt.Sprintf("%d %d", x, ans)) return } x := pp[l][0] + pp[r][0] for i := 0; i < n; i++ { ans += int64(pp[i][1]) * int64(abs(x-pp[i][0]*2)) } if x%2 == 0 { fmt.Fprintln(writer, fmt.Sprintf("%d %d", x/2, ans/2)) return } fmt.Fprintln(writer, fmt.Sprintf("%d.5 %d", x/2, ans/2)) } func abs(a int) int { if a < 0 { return -a } return a }