csansoon

P8.09 X17276 Increasing diagonals

Nov 29th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  typedef vector< vector<int> > Matrix;
  5.  
  6. int main(){
  7.     int n,m;
  8.     while (cin >> n >> m){
  9.        
  10.         Matrix diagonal(n, vector<int>(m));
  11.        
  12.         for (int i=0; i<n; ++i){
  13.             for (int j=0; j<m; ++j){
  14.                 cin >> diagonal[i][j];
  15.             }
  16.         }
  17.         bool one = false;
  18.         if (n==1 and m==1) one = true;
  19.         int posr, posc;
  20.         cin >> posr >> posc;
  21.         bool mp = true;
  22.         int num = diagonal[posr][posc];
  23.        
  24.         bool frst = true;
  25.        
  26.         for (int i=posr, j=posc; (i<n && j<m && mp) ; ++i, ++j){
  27.            
  28.             if (frst) frst = false;
  29.             else {
  30.                 if (num>=diagonal[i][j]) mp = false;
  31.                 else if (num<diagonal[i][j]) num = diagonal[i][j];
  32.             }          
  33.         }
  34.        
  35.         if (mp){
  36.             num = diagonal[posr][posc];
  37.             frst = true;
  38.             for (int i=posr, j=posc; (i>=0 && j<m && mp) ; --i, ++j){
  39.            
  40.                 if (frst) frst = false;
  41.                 else {
  42.                     if (num>=diagonal[i][j]) mp = false;
  43.                     else if (num<diagonal[i][j]) num = diagonal[i][j];
  44.                 }          
  45.             }
  46.             if (mp){
  47.                 num = diagonal[posr][posc];
  48.                 frst = true;
  49.            
  50.                 for (int i=posr, j=posc; (i<n && j>=0 && mp) ; ++i, --j){
  51.            
  52.                     if (frst) frst = false;
  53.                     else {
  54.                         if (num>=diagonal[i][j]) mp = false;
  55.                         else if (num<diagonal[i][j]) num = diagonal[i][j];
  56.                     }          
  57.                 }
  58.                 if (mp){
  59.                     num = diagonal[posr][posc];
  60.                     frst = true;
  61.            
  62.                     for (int i=posr, j=posc; (i>=0 && j>=0 && mp) ; --i, --j){
  63.            
  64.                         if (frst) frst = false;
  65.                         else {
  66.                             if (num>=diagonal[i][j]) mp = false;
  67.                             else if (num<diagonal[i][j]) num = diagonal[i][j];
  68.                         }          
  69.                     }
  70.                 }
  71.             }
  72.            
  73.         }
  74.        
  75.         if (one) cout << "yes"<<endl;
  76.         else{
  77.             if (mp) cout << "yes"<<endl;
  78.             else cout << "no"<<endl;
  79.         }      
  80.     }
  81. }
  82.  
  83. // (c) Carlos Sansón (Best pro1 delegate ever for sure) @csansoon
Advertisement
Add Comment
Please, Sign In to add comment