結果
| 問題 |
No.43 野球の試合
|
| コンテスト | |
| ユーザー |
ccppjsrb
|
| 提出日時 | 2020-07-09 10:55:43 |
| 言語 | Go (1.23.4) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 5,000 ms |
| コード長 | 2,381 bytes |
| コンパイル時間 | 14,117 ms |
| コンパイル使用メモリ | 222,864 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-06 13:03:58 |
| 合計ジャッジ時間 | 14,601 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 |
ソースコード
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)
ss := make([]string, n)
for i := 0; i < n; i++ {
ss[i] = getNextString(scanner)
}
b := 0
fixed := make([]int, n)
gg := make([]game, 0)
for i := 0; i < n; i++ {
for j := 0; j < i; j++ {
switch ss[i][j] {
case 'o':
fixed[i]++
case 'x':
fixed[j]++
case '-':
b++
gg = append(gg, game{y: i, x: j})
}
}
}
var ans int
ans = n
for i := 0; i < 1<<uint(b); i++ {
win := make([]int, n)
for j := 0; j < b; j++ {
if i>>uint(j)&1 == 0 {
win[gg[j].y]++
} else {
win[gg[j].x]++
}
}
for j := 0; j < n; j++ {
win[j] += fixed[j]
}
c := newCompress(win)
if ans > c.get(win[0]) {
ans = c.get(win[0])
}
}
fmt.Fprintln(writer, ans+1)
}
type compress map[int]int
func newCompress(aa []int) compress {
n := len(aa)
bb := make([]int, n)
copy(bb, aa)
sort.SliceStable(bb, func(i, j int) bool {
return bb[i] > bb[j]
})
c := compress{}
l := 0
i := 0
for r := 0; r < n; r++ {
for r > l && bb[r] != bb[l] {
l++
}
if r == l {
c[bb[l]] = i
i++
}
}
return c
}
func (c compress) get(x int) int {
return c[x]
}
type game struct {
y, x int
}
ccppjsrb