結果

問題 No.460 裏表ちわーわ
ユーザー 37zigen37zigen
提出日時 2016-12-11 02:54:09
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,186 bytes
コンパイル時間 2,635 ms
コンパイル使用メモリ 81,820 KB
実行使用メモリ 54,420 KB
最終ジャッジ日時 2024-05-06 18:17:27
合計ジャッジ時間 7,731 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
54,156 KB
testcase_01 AC 139 ms
54,144 KB
testcase_02 AC 144 ms
54,120 KB
testcase_03 AC 138 ms
53,780 KB
testcase_04 AC 136 ms
53,996 KB
testcase_05 AC 152 ms
54,072 KB
testcase_06 AC 148 ms
54,288 KB
testcase_07 AC 150 ms
53,984 KB
testcase_08 AC 145 ms
53,924 KB
testcase_09 AC 142 ms
53,908 KB
testcase_10 AC 148 ms
53,872 KB
testcase_11 AC 151 ms
54,292 KB
testcase_12 AC 149 ms
54,312 KB
testcase_13 WA -
testcase_14 AC 147 ms
53,964 KB
testcase_15 WA -
testcase_16 AC 148 ms
54,416 KB
testcase_17 AC 149 ms
54,204 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 143 ms
53,844 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 143 ms
53,988 KB
testcase_25 AC 141 ms
54,300 KB
testcase_26 AC 136 ms
53,968 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		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();
			}
		}

		int[][] mx = new int[M * N][M * N];
		int[] v = new int[M * N];
		for (int i = 0; i < M; ++i) {
			for (int j = 0; j < N; ++j) {
				v[i * N + j] = a[i][j];
			}
		}

		for (int i = 0; i < M; ++i) {
			for (int j = 0; j < N; ++j) {
				for (int dx = -1; dx <= 1; ++dx) {
					for (int dy = -1; dy <= 1; ++dy) {
						int nx = j + dx;
						int ny = i + dy;
						if (nx < 0 || ny < 0 || nx >= N || ny >= M)
							continue;
						mx[i * N + j][ny * N + nx] = 1;
					}
				}
			}
		}

		for (int i = 0; i < M * N; ++i) {
			int j = i;
			while (j < M * N && mx[j][i] == 0) {
				++j;
			}
			if (j == M * N)
				continue;
			if (i != j) {
				for (int k = 0; k < N * M; ++k) {
					int d = mx[i][k];
					mx[i][k] = mx[j][k];
					mx[j][k] = d;
				}
				int d = v[i];
				v[i] = v[j];
				v[j] = d;

			}
			for (int k = 0; k < M * N; ++k) {
				if (k == i)
					continue;
				if (mx[k][i] == 1) {
					for (int l = 0; l < M * N; ++l) {
						mx[k][l] = (mx[k][l] + mx[i][l]) % 2;
					}
					v[k] = (v[k] + v[i] + 2) % 2;
				}
			}
		}
		// show(mx, v, M, N);
		int c = 0;
		for (int i = N * M - 1; i >= 0; --i) {
			if (v[i] == 1) {
				if (mx[i][i] != 1) {
					System.out.println("Impossible");
					return;
				} else {
					++c;
					for (int k = 0; k <= i; ++k) {
						if (mx[k][i] == 1) {
							v[k] = v[k] ^ 1;
						}
					}
				}
			}
		}
		System.out.println(c);
	}

	static void show(int[][] mx, int[] v, int M, int N) {
		for (int i = 0; i < N * M; ++i) {
			if (i != 8 && i != 16)
				System.out.print("  ");
			else
				System.out.print("* ");
		}
		System.out.println();
		for (int i = 0; i < M * N; ++i) {
			for (int j = 0; j < M * N; ++j) {
				System.out.print(mx[i][j] + " ");
			}
			System.out.print(v[i]);
			System.out.println();
		}
	}

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