結果

問題 No.2639 Longest Increasing Walk
ユーザー tentententen
提出日時 2024-02-29 11:30:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 399 ms / 2,000 ms
コード長 2,428 bytes
コンパイル時間 7,076 ms
コンパイル使用メモリ 78,188 KB
実行使用メモリ 84,772 KB
最終ジャッジ日時 2024-02-29 11:30:29
合計ジャッジ時間 10,059 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,984 KB
testcase_01 AC 53 ms
53,992 KB
testcase_02 AC 53 ms
54,000 KB
testcase_03 AC 54 ms
53,992 KB
testcase_04 AC 331 ms
61,460 KB
testcase_05 AC 342 ms
61,516 KB
testcase_06 AC 353 ms
61,464 KB
testcase_07 AC 334 ms
61,992 KB
testcase_08 AC 325 ms
59,996 KB
testcase_09 AC 399 ms
84,772 KB
testcase_10 AC 271 ms
61,780 KB
testcase_11 AC 257 ms
60,252 KB
testcase_12 AC 142 ms
56,800 KB
testcase_13 AC 276 ms
60,288 KB
testcase_14 AC 221 ms
61,404 KB
testcase_15 AC 54 ms
53,984 KB
testcase_16 AC 100 ms
55,396 KB
testcase_17 AC 213 ms
61,352 KB
testcase_18 AC 236 ms
61,392 KB
testcase_19 AC 153 ms
59,156 KB
testcase_20 AC 193 ms
61,156 KB
testcase_21 AC 251 ms
60,516 KB
testcase_22 AC 175 ms
59,720 KB
testcase_23 AC 61 ms
54,128 KB
testcase_24 AC 62 ms
53,984 KB
testcase_25 AC 84 ms
54,640 KB
testcase_26 AC 55 ms
53,988 KB
testcase_27 AC 88 ms
54,764 KB
testcase_28 AC 54 ms
53,992 KB
testcase_29 AC 56 ms
53,988 KB
testcase_30 AC 55 ms
53,968 KB
testcase_31 AC 54 ms
53,992 KB
testcase_32 AC 55 ms
53,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    static int[][] dp;
    static int[][] field;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int h = sc.nextInt();
        int w = sc.nextInt();
        field = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                field[i][j] = sc.nextInt();
            }
        }
        dp = new int[h][w];
        int ans = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (dp[i][j] == 0) {
                    dp[i][j] = dfw(i, j);
                }
                ans = Math.max(ans, dp[i][j]);
            }
        }
        System.out.println(ans);
    }
    
    static int dfw(int r, int c) {
        if (dp[r][c] == 0) {
            int current = 0;
            if (r > 0 && field[r - 1][c] < field[r][c]) {
                current = Math.max(current, dfw(r - 1, c));
            }
            if (r < field.length - 1 && field[r + 1][c] < field[r][c]) {
                current = Math.max(current, dfw(r + 1, c));
            }
            if (c > 0 && field[r][c - 1] < field[r][c]) {
                current = Math.max(current, dfw(r, c - 1));
            }
            if (c < field[r].length - 1 && field[r][c + 1] < field[r][c]) {
                current = Math.max(current, dfw(r, c + 1));
            }
            dp[r][c] = current + 1;
        }
        return dp[r][c];
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0