結果

問題 No.452 横着者のビンゴゲーム
ユーザー yuki2006yuki2006
提出日時 2016-12-04 00:39:16
言語 Go
(1.21.3)
結果
WA  
実行時間 -
コード長 3,101 bytes
コンパイル時間 10,509 ms
コンパイル使用メモリ 204,432 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-18 13:59:36
合計ジャッジ時間 15,348 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 11 ms
5,352 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 16 ms
6,104 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 WA -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	M := sc.NextInt()
	matrix := make([][][]int, M)
	for i := 0; i < M; i++ {
		matrix[i] = make([][]int, N)
		for j := 0; j < N; j++ {
			matrix[i][j] = sc.NextIntArray()
		}
	}

	checkLine := func(typ int, p int, mp *map[int]struct{}) {

		switch {
		case typ < N:
			for i := 0; i < N; i++ {
				(*mp)[matrix[p][typ][i]] = struct{}{}
			}
		case typ < 2 * N:
			for i := 0; i < N; i++ {
				(*mp)[matrix[p][i][typ - N]] = struct{}{}
			}
		case typ == 2 * N:
			for i := 0; i < N; i++ {
				(*mp)[matrix[p][i][i]] = struct{}{}
			}
		case typ == 2 * N + 1:
			for i := 0; i < N; i++ {
				(*mp)[matrix[p][i][N - i - 1]] = struct{}{}
			}
		}
	}
	mx := 0
	for i := 0; i < M; i++ {
		for j := i + 1; j < M; j++ {
			for typ := 0; typ <= 2 * N + 1; typ++ {
				mp := map[int]struct{}{}

				checkLine(typ, i, &mp)
				for typ2 := 0; typ2 < 2 * N + 1; typ2++ {

					mp2 := map[int]struct{}{}
					for k2, v2 := range mp {
						mp2[k2] = v2
					}

					checkLine(typ2, j, &mp2)
					d := 2 * N - len(mp2)
					if mx < d {
						mx = d
					}
				}
			}
		}
	}
	fmt.Println(2 * N - mx - 1)

}

func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

0