Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("imagine.in");
- ofstream fout("imagine.out");
- int a[255][255], n;
- int s[255][255];
- void Citire()
- {
- int i, j;
- fin >> n;
- for(i = 1; i <= n; i++)
- for(j = 1; j <= n; j++)
- fin >> a[i][j];
- }
- void Prelucrare()
- {
- int i, j;
- for(i = 1; i <= n; i++)
- for(j = 1; j <= n; j++)
- s[i][j] = s[i-1][j] + s[i][j-1] + a[i][j] - s[i-1][j-1];
- }
- int Test(int l1, int c1, int l2, int c2)
- {
- if(l1 == l2 && c1 == c2) return 2;
- int S, nr;
- S = s[l2][c2] - s[l1-1][c2] - s[l2][c1-1] + s[l1-1][c1-1];
- nr = (l2 - l1 +1) * (c2 - c1 +1);
- if(S == 0 || S == nr) return 2;
- int lm, cm;
- lm = (l1 + l2) / 2;
- cm = (c1 + c2) / 2;
- return 1 + Test(lm+1,c1,l2,cm) + Test(l1,c1,lm,cm) + Test(lm+1,cm+1,l2,c2) + Test(l1,cm+1,lm,c2);
- }
- int main()
- {
- Citire();
- Prelucrare();
- fout<<Test(1, 1, n, n)<<"\n";
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement