結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー yukirinyukirin
提出日時 2016-02-27 22:11:41
言語 Go
(1.22.1)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 991 bytes
コンパイル時間 11,357 ms
コンパイル使用メモリ 233,416 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 06:24:14
合計ジャッジ時間 11,969 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	p := make([][]int, 6)
	dummy := []int{-1, -1, -1, -1, -1, -1}
	p[0], p[5] = dummy, dummy
	for i := 1; i < 5; i++ {
		p[i] = []int{-1, nextInt(), nextInt(), nextInt(), nextInt(), -1}
	}

	for i := 1; i < 5; i++ {
		for j := 1; j < 5; j++ {
			initI, initJ := (p[i][j]-1)/4+1, (p[i][j]-1)%4+1
			l := math.Abs(float64(i-initI)) + math.Abs(float64(j-initJ))
			if l > 1 && p[i][j] != 0 {
				fmt.Println("No")
				return
			}

			for _, pos := range [][2]int{{1, 0}, {0, 1}} {
				if p[i+pos[1]][j+pos[0]] == -1 {
					continue
				}

				next := ((i-1)*4 + j + (pos[1] * 4) + pos[0])
				if p[i][j] == next && p[i+pos[1]][j+pos[0]] == (i-1)*4+j {
					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