結果
問題 | No.766 金魚すくい |
ユーザー | ccppjsrb |
提出日時 | 2020-09-01 23:33:22 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 60 ms / 1,500 ms |
コード長 | 3,120 bytes |
コンパイル時間 | 11,546 ms |
コンパイル使用メモリ | 223,488 KB |
実行使用メモリ | 9,680 KB |
最終ジャッジ日時 | 2024-04-30 22:58:27 |
合計ジャッジ時間 | 13,792 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,812 KB |
testcase_02 | AC | 1 ms
6,812 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 1 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 56 ms
7,620 KB |
testcase_24 | AC | 57 ms
7,620 KB |
testcase_25 | AC | 59 ms
9,680 KB |
testcase_26 | AC | 53 ms
7,620 KB |
testcase_27 | AC | 60 ms
9,676 KB |
testcase_28 | AC | 54 ms
7,624 KB |
testcase_29 | AC | 57 ms
7,624 KB |
testcase_30 | AC | 56 ms
7,620 KB |
testcase_31 | AC | 60 ms
9,680 KB |
testcase_32 | AC | 53 ms
7,620 KB |
testcase_33 | AC | 43 ms
7,620 KB |
testcase_34 | AC | 43 ms
7,620 KB |
testcase_35 | AC | 3 ms
6,940 KB |
testcase_36 | AC | 3 ms
6,940 KB |
testcase_37 | AC | 57 ms
7,620 KB |
testcase_38 | AC | 55 ms
7,620 KB |
testcase_39 | AC | 59 ms
7,620 KB |
testcase_40 | AC | 54 ms
7,624 KB |
testcase_41 | AC | 41 ms
7,620 KB |
testcase_42 | AC | 39 ms
7,624 KB |
testcase_43 | AC | 2 ms
6,944 KB |
testcase_44 | AC | 1 ms
6,944 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) m := getNextInt(scanner) p := getNextInt(scanner) vv := make([]int64, n) for i := 0; i < n; i++ { vv[i] = getNextInt64(scanner) } sort.Slice(vv, func(i, j int) bool { return vv[i] > vv[j] }) var ans, sum, rest mint mc := newModcom(n + m) p1 := mint(100 - p).div(100) p2 := mint(p).div(100) pp := make([]mint, n+1) rest = 1 for i := 0; i < n; i++ { pp[i] = mc.choose(m+i-1, i) pp[i].mulAs(p1.pow(mint(i))) pp[i].mulAs(p2.pow(mint(m))) rest.subAs(pp[i]) ans.addAs(pp[i].mul(sum)) sum.addAs(mint(vv[i])) } ans.addAs(rest.mul(sum)) fmt.Fprintln(writer, ans) } type modcom struct { facs, invs []mint } func newModcom(n int) modcom { facs := make([]mint, n+1) invs := make([]mint, n+1) facs[0] = 1 for i := 0; i < n; i++ { facs[i+1] = facs[i].mul(mint(i + 1)) } invs[n] = facs[n].inv() for i := n - 1; i >= 0; i-- { invs[i] = invs[i+1].mul(mint(i + 1)) } return modcom{ facs: facs, invs: invs, } } func (mc *modcom) choose(n, k int) mint { return mc.facs[n].mul(mc.invs[k]).mul(mc.invs[n-k]) } type mint int64 func (mt mint) mod() mint { m := mint(1e9 + 7) mt %= m if mt < 0 { return mt + m } return mt } func (mt mint) inv() mint { return mt.pow(mint(0).sub(2)) } func (mt mint) pow(n mint) mint { p := mint(1) for n > 0 { if n&1 == 1 { p.mulAs(mt) } mt.mulAs(mt) n >>= 1 } return p } func (mt mint) add(x mint) mint { return (mt + x).mod() } func (mt mint) sub(x mint) mint { return (mt - x).mod() } func (mt mint) mul(x mint) mint { return (mt * x).mod() } func (mt mint) div(x mint) mint { return mt.mul(x.inv()) } func (mt *mint) addAs(x mint) *mint { *mt = mt.add(x) return mt } func (mt *mint) subAs(x mint) *mint { *mt = mt.sub(x) return mt } func (mt *mint) mulAs(x mint) *mint { *mt = mt.mul(x) return mt } func (mt *mint) divAs(x mint) *mint { *mt = mt.div(x) return mt }