Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 67 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     ios::sync_with_stdio(false);
  7.     cin.tie(0);
  8.     cout.tie(0);
  9.     int n,m,val;
  10.     int sumCM[1001][1001];
  11.     cin>>m>>n;
  12.     char aux;
  13.     for(int i = 0; i < m; i++){
  14.         for(int j = 0; j < n; j++){
  15.             cin>>aux;
  16.             if(aux == 'M'){
  17.                 sumCM[i][j] = 0;
  18.             }else if(aux == 'C'){  
  19.                 sumCM[i][j] = 1;
  20.             }
  21.         }
  22.     }
  23.     cin>>val;
  24.     int maxi = -1;
  25.         int SOMA[1001][1001];
  26.         for (int i = 0; i <= n; i++)
  27.         SOMA[0][i] = 0;
  28.         for (int i = 0; i <= m; i++)
  29.         SOMA[i][0] = 0;
  30.  
  31.         for (int i = 1; i <= n; i++){
  32.         SOMA[1][i] = SOMA[1][i-1] + sumCM[0][i-1];
  33.         }
  34.  
  35.         for (int i = 1; i <= m; i++){
  36.         SOMA[i][1] = SOMA[i-1][1] + sumCM[i-1][0];
  37.         }
  38.    
  39.         for(int i = 1; i <= m; i++){
  40.         for(int j = 1; j <= n; j++){   
  41.             SOMA[i][j] = SOMA[i-1][j] + SOMA[i][j-1]-SOMA[i-1][j-1]+sumCM[i-1][j-1];
  42.         }
  43.         }
  44.  
  45.         for(int i = val; i <= m ; i++){
  46.         for(int j = val; j <= n; j++){ 
  47.             int soma = SOMA[i][j] - (SOMA[i-val][j]+SOMA[i][j-val])+SOMA[i-val][j-val];
  48.             if(soma != 0 && soma != val*val)maxi = max(maxi,soma);
  49.         }
  50.         }
  51.         if(maxi == -1)cout<<-1<<endl;
  52.         else cout<<maxi*25+((val*val)-maxi)*12<<endl;
  53.  
  54.     return 0;
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top