結果

問題 No.460 裏表ちわーわ
ユーザー GrenacheGrenache
提出日時 2016-12-11 01:20:46
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,701 bytes
コンパイル時間 3,694 ms
コンパイル使用メモリ 80,248 KB
実行使用メモリ 351,500 KB
最終ジャッジ日時 2024-05-06 18:15:11
合計ジャッジ時間 10,206 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
46,548 KB
testcase_01 AC 398 ms
57,028 KB
testcase_02 AC 1,043 ms
105,308 KB
testcase_03 AC 122 ms
40,768 KB
testcase_04 AC 122 ms
41,552 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder460 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int m = sc.nextInt();
		int n = sc.nextInt();

		int[][] a = new int[m][n];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				a[i][j] = sc.nextInt();
			}
		}

		long st = enc(a);

		long[] conv = new long[m * n];
		int[][] tmp = new int[m][n];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				for (int ii = 0; ii < m; ii++) {
					for (int jj = 0; jj < n; jj++) {
						if (Math.abs(ii - i) <= 1 && Math.abs(jj - j) <= 1) {
							tmp[ii][jj] = 1;
						} else {
							tmp[ii][jj] = 0;
						}
					}
				}
				conv[i * n + j] = enc(tmp);
			}
		}

		int[][] ans = new int[m][n];
		long goal = enc(ans);

		Set<Long> hs = new HashSet<>();
		hs.add(goal);
		for (int i = 0; i < m * n * 2; i++) {
			if (hs.contains(st)) {
				pr.println(i);
				return;
			}

			Set<Long> hstmp = new HashSet<>();

			for (long e : hs) {
				for (long c : conv) {
					hstmp.add(e ^ c);
				}
			}
			hs = hstmp;
		}

		pr.println("Impossible");
	}

	private static long enc(int[][] a) {
		int m = a.length;
		int n = a[0].length;

		long tmp = 0;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				tmp <<= 1;
				if (a[i][j] == 1) {
					tmp |= 0x1;
				}
			}
		}

		return tmp;
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0