結果
問題 | No.662 スロットマシーン |
ユーザー | ccppjsrb |
提出日時 | 2020-07-16 20:34:05 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 134 ms / 2,000 ms |
コード長 | 2,691 bytes |
コンパイル時間 | 15,574 ms |
コンパイル使用メモリ | 237,816 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-05-04 01:05:25 |
合計ジャッジ時間 | 16,159 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 13 ms
5,376 KB |
testcase_03 | AC | 30 ms
5,376 KB |
testcase_04 | AC | 8 ms
5,376 KB |
testcase_05 | AC | 9 ms
5,376 KB |
testcase_06 | AC | 93 ms
5,376 KB |
testcase_07 | AC | 130 ms
5,376 KB |
testcase_08 | AC | 127 ms
5,376 KB |
testcase_09 | AC | 123 ms
5,376 KB |
testcase_10 | AC | 130 ms
5,376 KB |
testcase_11 | AC | 131 ms
5,376 KB |
testcase_12 | AC | 132 ms
5,376 KB |
testcase_13 | AC | 134 ms
5,376 KB |
testcase_14 | AC | 6 ms
5,376 KB |
testcase_15 | AC | 132 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 134 ms
5,376 KB |
testcase_18 | AC | 132 ms
5,376 KB |
ソースコード
package main import ( "bufio" "fmt" "math/big" "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) { yaku := 5 ss := make([]string, yaku) coins := make([]int, yaku) score := map[string]int64{} counter := map[string]int64{} for i := 0; i < yaku; i++ { ss[i] = getNextString(scanner) coins[i] = getNextInt(scanner) score[ss[i]] = int64(coins[i]) } aa := reel(scanner) bb := reel(scanner) cc := reel(scanner) var denom, num int64 denom = int64(sum(aa)) * int64(sum(bb)) * int64(sum(cc)) for a, cnta := range aa { for b, cntb := range bb { for c, cntc := range cc { count := int64(cnta) * int64(cntb) * int64(cntc) for i := 0; i < 3; i++ { if a[i] != b[i] { continue } if a[i] != c[i] { continue } counter[a[i]] += count num += count * score[a[i]] } if a[0] == b[1] && b[1] == c[2] { counter[a[0]] += count num += count * score[a[0]] } if a[2] == b[1] && b[1] == c[0] { counter[a[2]] += count num += count * score[a[2]] } } } } ex, _ := big.NewRat(num, denom).Float64() fmt.Fprintln(writer, ex) for i := 0; i < yaku; i++ { fmt.Fprintln(writer, counter[ss[i]]) } } type stop [3]string func sum(m map[stop]int) int { s := 0 for _, c := range m { s += c } return s } func reel(scanner *bufio.Scanner) map[stop]int { m := map[stop]int{} n := getNextInt(scanner) rr := make([]string, n) for i := 0; i < n; i++ { rr[i] = getNextString(scanner) } for i := 0; i < n; i++ { m[stop{rr[i], rr[(i+1)%n], rr[(i+2)%n]}]++ } return m }