結果
| 問題 | No.228 ゆきこちゃんの 15 パズル | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-02-27 21:14:41 | 
| 言語 | Go (1.23.4) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1 ms / 5,000 ms | 
| コード長 | 1,114 bytes | 
| コンパイル時間 | 11,848 ms | 
| コンパイル使用メモリ | 237,940 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-10 23:03:42 | 
| 合計ジャッジ時間 | 12,655 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
ソースコード
package main
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func main() {
	sc.Split(bufio.ScanWords)
	p := make([][]int, 6)
	p[0] = []int{-1, -1, -1, -1, -1, -1}
	p[5] = []int{-1, -1, -1, -1, -1, -1}
	for i := 1; i < 5; i++ {
		p[i] = []int{-1, nextInt(), nextInt(), nextInt(), nextInt(), -1}
	}
	ns := [][2]int{{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {0, 0}}
	for i := 1; i < 5; i++ {
		for j := 1; j < 5; j++ {
			n := (i-1)*4 + j
			if n == 16 {
				continue
			}
			adj := false
			for _, pos := range ns {
				nI, nJ := i+pos[1], j+pos[0]
				if p[nI][nJ] == n {
					adj = true
					break
				}
			}
			if !adj {
				fmt.Println("No")
				return
			}
			for _, pos := range ns[:2] {
				if p[i+pos[1]][j+pos[0]] == -1 {
					continue
				}
				next := (n + (pos[1] * 4) + pos[0])
				if n == 16 {
					continue
				}
				if p[i][j] == next && p[i+pos[1]][j+pos[0]] == n {
					fmt.Println("No")
					return
				}
			}
		}
	}
	fmt.Println("Yes")
}
func nextLine() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}
            
            
            
        