Advertisement
Nita_Cristian

Pavaj 2902

Apr 13th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream fin("pavaj.in");
  4. ofstream fout("pavaj.out");
  5. int s[1001][1001];
  6. int main()
  7. {
  8.     int n,m,i,j,k,sum=0,l1=0,l2=0,c1=0,c2=0;
  9.     fin>>n>>m>>k;
  10.     for(i=1;i<=n;i++)
  11.     {
  12.         for(j=1;j<=m;j++)
  13.         {
  14.             fin>>s[i][j];
  15.             s[i][j]=s[i][j]+s[i-1][j]+s[i][j-1]-s[i-1][j-1];
  16.         }
  17.     }
  18.     for(i=1;i<=k;i++)
  19.     {
  20.         fin>>l1>>c1>>l2>>c2;
  21.         if(c1>c2)
  22.         {
  23.             swap(c1,c2);
  24.         }
  25.         if(l1>l2)
  26.         {
  27.             swap(l1,l2);
  28.         }
  29.         sum=s[l2][c2]-s[l1-1][c2]-s[l2][c1-1]+s[l1-1][c1-1];
  30.         if(sum==0)
  31.         {
  32.             fout<<0<<'\n';
  33.         }
  34.         else
  35.         {
  36.             if(sum==(l2-l1+1)*(c2-c1+1))
  37.                {
  38.                    fout<<1<<'\n';
  39.                }
  40.             else
  41.                 {
  42.                     fout<<2<<'\n';
  43.  
  44.                 }
  45.         }
  46.     }
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement