睦星科技挑战赛 register

Ended

Participants:114

Verdict:Accepted
Score:100 / 100
Submitted:2019-05-25 11:09:24

Lang:Java

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()) {
            int height = in.nextInt();
            int width = in.nextInt();
            int[][] city = new int[height][width];
            for(int m = 0;m < height;m++){
                for(int n = 0;n < width;n++){
                    city[m][n= in.nextInt();
                }
            }
            System.out.println(maximalSquare(city));
        }
    }
    public static int maximalSquare(int[][] city) {
        int rows = city.lengthcols = rows > 0 ? city[0].length : 0;
        int[][] dp = new int[rows + 1][cols + 1];
        int maxsqlen = 0;
        for (int i = 1i <= rowsi++) {
            for (int j = 1j <= colsj++) {
                if (city[i-1][j-1== 1){
                    dp[i][j= Math.min(Math.min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;
                    maxsqlen = Math.max(maxsqlendp[i][j]);
                }
            }
        }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX