Submission #669112


Source Code Expand

import java.util.*;

public class Main {

    static final int MAX = 30;
    static Point[][] board = new Point[MAX][MAX];
    static List<Point> list = new ArrayList<>();
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < MAX; i++) {
            for (int j = 0; j < MAX; j++) {
                Point point = new Point();
                point.x = i;
                point.y = j;
                point.value = sc.nextInt();
                board[i][j] = point;
                list.add(point);
            }
        }
        while (true) {
            list.sort((p1, p2) -> Integer.compare(p1.value, p2.value) * -1);
            int firstValue = list.get(0).value;
            if (firstValue == 0) {
                return;
            }
            List<Point> answerList = new ArrayList<>();
            for (Point point :list) {
                if (point.value < firstValue) {
                    break;
                }
                
                List<Point> resultList = new ArrayList<>();
                resultList.add(point);
                resultList = test(resultList);
                if (answerList.size() < resultList.size()) {
                    answerList = resultList;
                }
            }
            for (Point point :answerList) {
                System.out.println(point.xy());
                point.value--;
            }
//            for (int i = 0; i < MAX; i++) {
//                for (int j = 0; j < MAX; j++) {
//                    System.out.print(board[i][j] + " ");
//                }
//                System.out.println();
//            }
        }
    }
    static List<Point> test(List<Point> pointList) {
        List<Point> nextList = pointList;
        Point point = pointList.get(pointList.size() - 1);
        int nextValue = point.value - 1;
        if (nextValue > 0) {
            if (point.x - 1 >= 0 && board[point.x - 1][point.y].value == nextValue) {
                Point next = board[point.x - 1][point.y];
                if (!pointList.contains(next)) {
                    List<Point> westList = new ArrayList<>();
                    for (Point p : pointList) {
                        westList.add(p);
                    }
                    westList.add(next);
                    westList = test(westList);
                    if (nextList.size() < westList.size()) {
                        nextList = westList;
                    }
                }
            }
            if (point.x + 1 < MAX && board[point.x + 1][point.y].value == nextValue) {
                Point next = board[point.x + 1][point.y];
                if (!pointList.contains(next)) {
                    List<Point> eastList = new ArrayList<>();
                    for (Point p : pointList) {
                        eastList.add(p);
                    }
                    eastList.add(next);
                    eastList = test(eastList);
                    if (nextList.size() < eastList.size()) {
                        nextList = eastList;
                    }
                }
            }
            if (point.y - 1 >= 0 && board[point.x][point.y - 1].value == nextValue) {
                Point next = board[point.x][point.y - 1];
                if (!pointList.contains(next)) {
                    List<Point> eastList = new ArrayList<>();
                    for (Point p : pointList) {
                        eastList.add(p);
                    }
                    eastList.add(next);
                    eastList = test(eastList);
                    if (nextList.size() < eastList.size()) {
                        nextList = eastList;
                    }
                }
            }
            if (point.y + 1 < MAX && board[point.x][point.y + 1].value == nextValue) {
                Point next = board[point.x][point.y + 1];
                if (!pointList.contains(next)) {
                    List<Point> eastList = new ArrayList<>();
                    for (Point p : pointList) {
                        eastList.add(p);
                    }
                    eastList.add(next);
                    eastList = test(eastList);
                    if (nextList.size() < eastList.size()) {
                        nextList = eastList;
                    }
                }
            }
        }
        return nextList;
    }
    
    static class Point {
        public int x;
        public int y;
        public int value;
        public String xy() {
            return (x + 1) + " " + (y + 1);
        }
        @Override
        public String toString() {
            return "(" + (x + 1) + ", " + (y + 1) + ") = " + value;
        }
    }
}

Submission Info

Submission Time
Task A - 高橋君の山崩しゲーム
User tksy
Language Java8 (OpenJDK 1.8.0)
Score 829480
Code Size 4855 Byte
Status AC
Exec Time 2444 ms
Memory 45808 KiB

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 82759 / 100000 83041 / 100000 83281 / 100000 82478 / 100000 82942 / 100000 82338 / 100000 83369 / 100000 83008 / 100000 82968 / 100000 83296 / 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 2148 ms 42088 KiB
subtask_01_02.txt AC 2052 ms 43532 KiB
subtask_01_03.txt AC 2049 ms 43592 KiB
subtask_01_04.txt AC 1961 ms 36216 KiB
subtask_01_05.txt AC 2149 ms 42012 KiB
subtask_01_06.txt AC 1979 ms 33024 KiB
subtask_01_07.txt AC 2061 ms 41744 KiB
subtask_01_08.txt AC 2444 ms 45808 KiB
subtask_01_09.txt AC 2148 ms 43352 KiB
subtask_01_10.txt AC 1940 ms 40240 KiB