Advertisement
Guest User

1973

a guest
Apr 20th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. /*
  2. Popa Bogdan Ioan, Colegiul National Aurel Vlaicu
  3. clasa a 10-a
  4. Sume partiale, O(N^2)
  5. */
  6. #include <bits/stdc++.h>
  7. #define nmax 1002
  8. using namespace std;
  9. ifstream fin("hambar2.in");
  10. ofstream fout("hambar2.out");
  11. int n, M;
  12. int i, j, k;
  13. int L;
  14. bitset<nmax>a[nmax];
  15. short S[nmax][nmax];
  16. int maxarie;
  17. short ct[nmax];
  18. int idx;
  19. int main()
  20. {
  21. fin >> n >> M;
  22. while(M--)
  23. {
  24. fin >> i >> j;
  25. a[i][j] = 1;
  26. }
  27. for(j = 1; j <= n; j++)
  28. {
  29. for(i = 1, k = 0; i <= n; i++)
  30. {
  31. if(a[i][j] == 0)
  32. S[i][j] = 1 + S[i][j - 1];
  33. while(k && S[ct[k]][j] > S[i][j])
  34. {
  35. idx = ct[k--];
  36. maxarie = max(maxarie, (i - ct[k] - 1) * S[idx][j]);
  37. }
  38. ct[++k] = i;
  39. }
  40. while(k)
  41. {
  42. idx = ct[k--];
  43. maxarie = max(maxarie, (n - ct[k]) * S[idx][j]);
  44. }
  45. }
  46. fout << maxarie << "\n";
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement