GCJ2011 Round 1C A "Square Tiles"

問題:https://code.google.com/codejam/contest/dashboard?c=1128486#s=p0

Google Code Jam nise..nabeで参加.

白と青で着色された長方形が与えられる.この青の部分を2x2のサイズで赤に塗り替えるとき,塗り替えた結果を求める.

単に左上から2x2のサイズで塗り替えるだけ.無駄にLargeを二回提出してしまってしょんぼりしてた.

コード

import java.util.*;

public class A {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		for (int t = 1, T = s.nextInt(); t <= T; ++t) {
			int h = s.nextInt(), w = s.nextInt();
			char[][] cs = new char[h][];
			for (int i = 0; i < h; ++i) {
				cs[i] = s.next().toCharArray();
			}
			for (int i = 0; i < h - 1; ++i) {
				for (int j = 0; j < w - 1; ++j) {
					if (cs[i][j] == '#' && cs[i + 1][j] == '#'
							&& cs[i][j + 1] == '#' && cs[i + 1][j + 1] == '#') {
						cs[i][j] = cs[i + 1][j + 1] = '/';
						cs[i + 1][j] = cs[i][j + 1] = '\\';
					}
				}
			}

			boolean b = true;
			for (int i = 0; i < h; ++i) {
				for (int j = 0; j < w; ++j) {
					if (cs[i][j] == '#') {
						b = false;
					}
				}
			}

			System.out.println("Case #" + t + ":");
			if (b) {
				for (char[] c : cs) {
					System.out.println(new String(c));
				}
			} else {
				System.out.println("Impossible");
			}
		}
	}
}