結果

問題 No.585 工夫のないパズル
ユーザー 37zigen37zigen
提出日時 2017-11-09 03:00:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 2,842 bytes
コンパイル時間 3,060 ms
コンパイル使用メモリ 77,356 KB
実行使用メモリ 57,276 KB
最終ジャッジ日時 2023-08-15 21:26:48
合計ジャッジ時間 6,007 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 159 ms
57,276 KB
testcase_01 AC 163 ms
57,196 KB
testcase_02 AC 155 ms
56,972 KB
testcase_03 AC 152 ms
57,060 KB
testcase_04 AC 162 ms
57,124 KB
testcase_05 AC 153 ms
57,056 KB
testcase_06 AC 153 ms
56,960 KB
testcase_07 AC 152 ms
56,756 KB
testcase_08 AC 153 ms
57,016 KB
testcase_09 AC 153 ms
56,720 KB
testcase_10 AC 152 ms
56,996 KB
testcase_11 AC 152 ms
54,816 KB
testcase_12 AC 157 ms
57,096 KB
testcase_13 AC 153 ms
56,744 KB
testcase_14 AC 154 ms
56,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	static int cnt = 0;

	static void run() {
		Scanner sc = new Scanner(System.in);
		char[][] m = new char[4][4];
		for (int i = 0; i < 4; ++i) {
			m[i] = sc.next().toCharArray();
		}
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 4 && 4 * i + j <= 12; ++j) {
				if (m[i][j] == (char) ('A' + 4 * i + j))
					continue;
				for (int k = 0; k < 4; ++k) {
					for (int l = 0; l < 4; ++l) {
						if (m[k][l] != (char) ('A' + 4 * i + j))
							continue;
						if (3 - k > 0) {
							m = toLower(l, 3 - k, m);
						}
						int g = 1;
						if ((j - 1 + 4) % 4 != l) {
							int d = (j - 1 - l >= 0 ? (j - 1 - l) : 4 + j - 1 - l);
							if (d != 0) {
								m = toRight(3, d, m);
							}
						} else {
							g = 3;
							int d = (j + 1 - l >= 0 ? (j + 1 - l) : 4 + j + 1 - l);
							if (d != 0) {
								m = toRight(3, d, m);
							}
						}
						if (k + 1 <= 3)
							m = toLower(l, k + 1, m);

						if (3 - i > 0) {
							m = toLower(j, 3 - i, m);
						}
						m = toRight(3, g, m);
						if (i + 1 <= 3)
							m = toLower(j, i + 1, m);
					}
				}
			}
		}

		while (m[3][1] != 'N') {
			m = toRight(3, 1, m);
			m = toLower(3, 1, m);
			m = toRight(3, 3, m);
			m = toLower(3, 3, m);
			m = toRight(3, 2, m);
			m = toLower(3, 1, m);
			m = toRight(3, 2, m);
			m = toLower(3, 3, m);
			m = toLower(3, 1, m);
			m = toRight(3, 1, m);
			m = toLower(3, 3, m);
			m = toRight(3, 3, m);
		}
		if (m[3][2] != 'O') {
			for (int t = 0; t < 2; ++t) {
				m = toLower(0, 1, m);
				m = toRight(3, 1, m);
				m = toLower(0, 3, m);
				if (t == 0)
					m = toRight(3, 2, m);
				else
					m = toRight(3, 1, m);
			}
		}
		System.out.println(cnt);
		System.out.println(ans);
	}

	static StringBuilder ans = new StringBuilder();

	static char[][] toRight(int r, int a, char[][] m) {
		if (!(0 <= r && r <= 3) || !(1 <= a && a <= 3))
			throw new AssertionError();
		ans.append("R " + r + " " + a + "\n");
		char[][] ret = new char[4][4];
		for (int i = 0; i < 4; ++i)
			for (int j = 0; j < 4; ++j)
				ret[i][j] = m[i][j];
		for (int i = 0; i < 4; ++i) {
			ret[r][i] = m[r][(i - a + 4) % 4];
		}
		++cnt;
		return ret;
	}

	static char[][] toLower(int c, int b, char[][] m) {
		if (!(0 <= c && c <= 3) || !(1 <= b && b <= 3))
			throw new AssertionError();
		ans.append("C " + c + " " + b + "\n");
		char[][] ret = new char[4][4];
		for (int i = 0; i < 4; ++i)
			for (int j = 0; j < 4; ++j)
				ret[i][j] = m[i][j];
		for (int i = 0; i < 4; ++i) {
			ret[i][c] = m[(i - b + 4) % 4][c];
		}
		++cnt;
		return ret;
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	static void trMap(char[][] m) {
		for (char[] a : m) {
			tr(a);
		}
	}
}
0