結果

問題 No.832 麻雀修行中
ユーザー ccppjsrbccppjsrb
提出日時 2020-08-25 17:41:10
言語 Go
(1.22.1)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 2,504 bytes
コンパイル時間 12,560 ms
コンパイル使用メモリ 234,680 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 04:40:12
合計ジャッジ時間 14,053 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
5,248 KB
testcase_01 AC 13 ms
5,248 KB
testcase_02 AC 11 ms
5,376 KB
testcase_03 AC 15 ms
5,376 KB
testcase_04 AC 18 ms
5,376 KB
testcase_05 AC 15 ms
5,376 KB
testcase_06 AC 17 ms
5,376 KB
testcase_07 AC 18 ms
5,376 KB
testcase_08 AC 18 ms
5,376 KB
testcase_09 AC 16 ms
5,376 KB
testcase_10 AC 15 ms
5,376 KB
testcase_11 AC 15 ms
5,376 KB
testcase_12 AC 18 ms
5,376 KB
testcase_13 AC 21 ms
5,376 KB
testcase_14 AC 13 ms
5,376 KB
testcase_15 AC 17 ms
5,376 KB
testcase_16 AC 16 ms
5,376 KB
testcase_17 AC 15 ms
5,376 KB
testcase_18 AC 18 ms
5,376 KB
testcase_19 AC 16 ms
5,376 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 15 ms
5,376 KB
testcase_22 AC 18 ms
5,376 KB
testcase_23 AC 14 ms
5,376 KB
testcase_24 AC 15 ms
5,376 KB
testcase_25 AC 18 ms
5,376 KB
testcase_26 AC 19 ms
5,376 KB
testcase_27 AC 11 ms
5,376 KB
testcase_28 AC 19 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 18 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"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) {
	s := getNextString(scanner)
	n := 13
	pp := make([]int, 10)
	for i := 0; i < n; i++ {
		pp[int(s[i]-'0')]++
	}
	mm := make([][3]int, 0)
	for i := 1; i < 8; i++ {
		mm = append(mm, [3]int{i, i + 1, i + 2})
	}
	for i := 1; i < 10; i++ {
		mm = append(mm, [3]int{i, i, i})
	}
	ans := make([]int, 0)
	for i := 1; i < 10; i++ {
		if pp[i] == 4 {
			continue
		}
		pp[i]++
		if designedchildren(pp) || lohengrin(pp, mm) {
			ans = append(ans, i)
		}
		pp[i]--
	}
	for i := 0; i < len(ans); i++ {
		fmt.Fprintln(writer, ans[i])
	}
}
func designedchildren(pp []int) bool {
	p := 0
	for i := 1; i < 10; i++ {
		if pp[i] == 2 {
			p++
		}
	}
	return p == 7
}
func lohengrin(pp []int, mm [][3]int) bool {
	n := len(mm)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			for k := 0; k < n; k++ {
				for l := 0; l < n; l++ {
					rr := make([]int, 10)
					for c := 0; c < 3; c++ {
						rr[mm[i][c]]++
						rr[mm[j][c]]++
						rr[mm[k][c]]++
						rr[mm[l][c]]++
					}
					if valid(pp, rr) {
						return true
					}
				}
			}
		}
	}
	return false
}

func valid(pp, rr []int) bool {
	v := true
	for i := 0; i < 10; i++ {
		pp[i] -= rr[i]
	}
	for i := 0; i < 10; i++ {
		if pp[i] < 0 || pp[i] == 1 {
			v = false
			break
		}
	}
	for i := 0; i < 10; i++ {
		pp[i] += rr[i]
	}
	return v
}
0