Submission #2061013


Source Code Expand

import java.util.Scanner;

/**
 * chokudai contest1
 * @author tsukammo
 */
public class Main {
	final static int row = 30, col = 30; // map size

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

	int[][] map = new int[row][col];

	// 変更
	void solve() {
		input();
		//solveFool();
		solveWisdom();
	}

	// 4方向探索用
	final static int[] dx = new int[] { 1, 0, 0, -1 };
	final static int[] dy = new int[] { 0, 1, -1, 0 };

	void solveWisdom() {
		int[] p = chooseTop();
		while (p != null) {
			// 可能な限り連続で崩す
			while (true) {
				int x = p[0];
				int y = p[1];
				System.out.println((x + 1) + " " + (y + 1));
				map[x][y]--;
				// 4方向探索
				int[] next = null;
				for (int d = 0; d < dx.length; d++) {
					int nx = x + dx[d];
					int ny = y + dy[d];
					if (outMap(nx, ny)) {
						continue;
					}
					if (map[x][y] == map[nx][ny] && map[nx][ny] > 0) {
						next = new int[] { nx, ny };
						break;
					}
				}
				if (next != null) {
					p = next;
					continue;
				}
				break;
			}
			p = chooseTop();
		}
	}

	// 山のてっぺんを探す
	int[] chooseTop() {
		for (int i = 0; i < row; i++) {
			for (int j = 0; j < col; j++) {
				if (isTop(i, j)) {
					return new int[] { i, j };
				}
			}
		}
		return null;
	}

	// 山のてっぺんかを判定
	boolean isTop(int x, int y) {
		for (int d = 0; d < dx.length; d++) {
			int nx = x + dx[d];
			int ny = y + dy[d];
			if (outMap(nx, ny)) {
				continue;
			}
			if (map[x][y] <= 0 || map[nx][ny] > map[x][y]) {
				return false;
			}
		}
		return true;
	}

	// 場外判定
	boolean outMap(int x, int y) {
		return !(x > -1 && y > -1 && x < row && y < col);
	}

	void input() {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		for (int i = 0; i < row; i++) {
			for (int j = 0; j < col; j++) {
				map[i][j] = sc.nextInt();
			}
		}
	}

	void solveFool() {
		for (int i = 0; i < row; i++) {
			for (int j = 0; j < col; j++) {
				while (map[i][j]-- > 0) {
					System.out.println((i + 1) + " " + (j + 1));
				}
			}
		}
	}
}

Submission Info

Submission Time
Task A - 高橋君の山崩しゲーム
User tsukammo
Language Java8 (OpenJDK 1.8.0)
Score 800640
Code Size 2193 Byte
Status AC
Exec Time 546 ms
Memory 36456 KB

Judge Result

Set Name test_01 test_02 test_03 test_04 test_05 test_06 test_07 test_08 test_09 test_10
Score / Max Score 79973 / 100000 79417 / 100000 80928 / 100000 78928 / 100000 80581 / 100000 80021 / 100000 80558 / 100000 80290 / 100000 80166 / 100000 79778 / 100000
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
test_01 subtask_01_01.txt
test_02 subtask_01_02.txt
test_03 subtask_01_03.txt
test_04 subtask_01_04.txt
test_05 subtask_01_05.txt
test_06 subtask_01_06.txt
test_07 subtask_01_07.txt
test_08 subtask_01_08.txt
test_09 subtask_01_09.txt
test_10 subtask_01_10.txt
Case Name Status Exec Time Memory
subtask_01_01.txt AC 508 ms 33688 KB
subtask_01_02.txt AC 528 ms 34108 KB
subtask_01_03.txt AC 514 ms 35904 KB
subtask_01_04.txt AC 535 ms 34744 KB
subtask_01_05.txt AC 525 ms 36456 KB
subtask_01_06.txt AC 524 ms 35296 KB
subtask_01_07.txt AC 521 ms 33944 KB
subtask_01_08.txt AC 529 ms 34568 KB
subtask_01_09.txt AC 534 ms 34992 KB
subtask_01_10.txt AC 546 ms 35812 KB