Advertisement
red_grave

BugLife#1-C

Jan 18th, 2021
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.60 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. public class Main
  6. {
  7.     public static void process(int test_number)throws IOException
  8.     {
  9.         int n = ni(), m = ni();
  10.         int dp[][][] = new int[n + 1][m + 1][4 + 1], arr[][] = new int[n + 1][m + 1], res = 0;
  11.  
  12.         for(int i = 1; i <= n; i++)
  13.             for(int j = 1; j <= m; j++){
  14.                 arr[i][j] = ni();
  15.                 dp[i][j][arr[i][j]] = 1;
  16.             }
  17.  
  18.         for(int i = 1; i <= n; i++){
  19.             for(int j = 1; j <= m; j++){
  20.                 int num = arr[i][j];
  21.                 dp[i][j][num] += Math.min(dp[i - 1][j][num], Math.min(dp[i][j - 1][num], dp[i - 1][j - 1][num]));
  22.                 res = Math.max(res, dp[i][j][num]);
  23.             }
  24.         }
  25.  
  26.         p(res + "\n");
  27.     }
  28.  
  29.     static final long mod = (long)1e9+7l;
  30.     static boolean DEBUG = true;
  31.     static FastReader sc;
  32.     static PrintWriter out;
  33.     public static void main(String[]args)throws IOException
  34.     {
  35.         out = new PrintWriter(System.out);
  36.         sc = new FastReader();
  37.  
  38.         long s = System.currentTimeMillis();
  39.         int t = 1;
  40.         // t = ni();
  41.         for(int i = 1; i <= t; i++)
  42.             process(i);
  43.  
  44.         out.flush();
  45.         System.err.println(System.currentTimeMillis()-s+"ms");
  46.     }
  47.  
  48.     static void trace(Object... o){ if(!DEBUG) return; System.err.println(Arrays.deepToString(o)); };    
  49.     static void pn(Object o){ out.println(o); }
  50.     static void p(Object o){ out.print(o); }
  51.     static int ni()throws IOException{ return Integer.parseInt(sc.next()); }
  52.     static long nl()throws IOException{ return Long.parseLong(sc.next()); }
  53.     static double nd()throws IOException{ return Double.parseDouble(sc.next()); }
  54.     static String nln()throws IOException{ return sc.nextLine(); }
  55.     static long gcd(long a, long b){ return (b==0)?a:gcd(b,a%b);}
  56.     static int gcd(int a, int b){ return (b==0)?a:gcd(b,a%b); }
  57.    
  58.     static class FastReader{
  59.         BufferedReader br;
  60.         StringTokenizer st;
  61.  
  62.         public FastReader(){
  63.             br = new BufferedReader(new InputStreamReader(System.in));
  64.         }
  65.  
  66.         String next(){
  67.             while (st == null || !st.hasMoreElements()){
  68.                 try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); }
  69.             }
  70.             return st.nextToken();
  71.         }
  72.  
  73.         String nextLine(){
  74.             String str = "";
  75.             try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); }
  76.             return str;
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement