結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー yukirinyukirin
提出日時 2016-02-27 21:14:41
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,114 bytes
コンパイル時間 11,402 ms
コンパイル使用メモリ 226,896 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 06:23:10
合計ジャッジ時間 12,001 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,820 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
}
0