Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class LargesAreaInMatrix {
- public static void main(String[] args) throws Exception {
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- String[] tokens = in.readLine().split(" ");
- int a = Integer.parseInt(tokens[0]);
- int b = Integer.parseInt(tokens[1]);
- int[][] array=new int[a][b];
- for(int i=0;i<a;i++){
- String[] numbers = in.readLine().split(" ");
- for(int j=0;j<b;j++){
- array[i][j]=Integer.parseInt(numbers[j]);
- }
- }
- int maxSum[][]=new int[1024][1];
- for(int i=0;i<1024;i++){
- maxSum[i][0]=Integer.MIN_VALUE;
- }
- int currentSum[][]=new int[1024][1];
- for(int i=1;i<a-1;i++){
- for(int j=1;j<b-1;j++){
- int aray=array[i][j];
- currentSum[aray][0]+=neighbours(array,i,j);
- if(maxSum[aray][0]<=currentSum[aray][0]){
- maxSum[aray][0]=currentSum[aray][0];
- }
- }
- }
- int maxxSum=Integer.MIN_VALUE;
- for(int i=0;i<1024;i++){
- if(maxxSum<=maxSum[i][0]){
- maxxSum=maxSum[i][0];
- }
- }
- System.out.println(maxxSum);
- }
- public static int neighbours(int[][] arraySum,int row,int col){
- int sum=0;
- if(arraySum[row][col]==arraySum[row+1][col]){
- sum++;
- }
- if(arraySum[row][col]==arraySum[row][col+1]){
- sum++;
- }
- if(arraySum[row][col]==arraySum[row-1][col]){
- sum++;
- }
- if(arraySum[row][col]==arraySum[row][col-1]){
- sum++;
- }
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement