結果

問題 No.452 横着者のビンゴゲーム
ユーザー yuki2006yuki2006
提出日時 2016-12-04 00:42:02
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 3,097 bytes
コンパイル時間 9,460 ms
コンパイル使用メモリ 210,872 KB
実行使用メモリ 8,428 KB
最終ジャッジ日時 2023-08-18 14:00:05
合計ジャッジ時間 22,349 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
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 AC 1,274 ms
7,280 KB
testcase_15 AC 1,256 ms
7,276 KB
testcase_16 AC 770 ms
7,056 KB
testcase_17 AC 35 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 78 ms
6,728 KB
testcase_21 WA -
testcase_22 AC 56 ms
6,488 KB
testcase_23 WA -
testcase_24 AC 26 ms
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 58 ms
6,704 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 131 ms
6,788 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

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 typ := 0; typ <= 2 * N + 1; typ++ {
			mp := map[int]struct{}{}

			checkLine(typ, i, &mp)


			for j := i + 1; j < M; j++ {
				mp2 := map[int]struct{}{}
				for k2, v2 := range mp {
					mp2[k2] = v2
				}

				for typ2 := 0; typ2 < 2 * N + 1; typ2++ {

					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