結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー plainbananaplainbanana
提出日時 2019-03-15 02:04:13
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 1,229 bytes
コンパイル時間 12,237 ms
コンパイル使用メモリ 206,676 KB
実行使用メモリ 10,148 KB
最終ジャッジ日時 2023-09-09 23:44:20
合計ジャッジ時間 55,254 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,294 ms
8,144 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
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 AC 1,367 ms
10,040 KB
testcase_17 AC 1,377 ms
10,148 KB
testcase_18 AC 1,374 ms
9,980 KB
testcase_19 AC 2,094 ms
8,120 KB
testcase_20 AC 2,117 ms
8,072 KB
testcase_21 AC 2,095 ms
8,064 KB
testcase_22 AC 1,247 ms
9,652 KB
testcase_23 AC 1,310 ms
10,040 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

// 任意の要素数の文字列を読み込んでスライスで返す
func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		fmt.Scanf("%s", &str)
		strings = append(strings, str)
	}
	return
}

// 任意の要素数の配列を読み込んでスライスで返す
func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func flag(mid float64, k int, ll []int) bool {
	sum := 0
	for _, v := range ll {
		sum += int(float64(v) / mid)
	}
	// fmt.Println("sum:", sum)
	if sum >= k {
		return true
	}
	return false
}

func main() {
	n := scanNums(1)[0]
	ll := scanNums(n)
	k := scanNums(1)[0]

	l := 0.0
	r := 1e10
	for i := 0; i < 100 && r-l > 1e-10; i++ {
		mid := (r + l) / 2.0
		if flag(mid, k, ll) {
			l = mid
			// fmt.Println("true mid:", mid)
		} else {
			r = mid
		}
	}

	// fmt.Println("n,l,k,ll", n, l, k, ll)
	fmt.Printf("%.2f\n", l)
}
0