-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest1915.java
More file actions
43 lines (40 loc) · 1.24 KB
/
test1915.java
File metadata and controls
43 lines (40 loc) · 1.24 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
//https://www.acmicpc.net/problem/1915
package org.tryAgain;
import java.util.Scanner;
public class test1915 {
static int n,m,ans;
static String s;
static int[][] a = new int[1001][1001], d = new int [1001][1001];
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
m = in.nextInt();
for(int i=0; i<n; i++){
s = in.next();
for(int j=0; j<m; j++){
a[i][j] = s.charAt(j)-48;
if(a[i][j]==1){
d[i][j] = 1;
ans = 1;
}
}
}
for(int i=1; i<n; i++){
for(int j=1; j<m; j++){
if(a[i-1][j]==1 && a[i-1][j-1]==1 && a[i][j-1]==1){
d[i][j] = Math.min(d[i-1][j], d[i-1][j-1]);
d[i][j] = Math.min(d[i][j], d[i][j-1]) + 1;
}
ans = Math.max(d[i][j], ans);
}
}
for(int i=0; i<n;i++) {
for(int j=0; j<m; j++) {
System.out.print(d[i][j]+" ");
}
System.out.println();
}
System.out.println(ans*ans);
in.close();
}
}