Submission #51233

#TimeUsernameProblemLanguageResultExecution timeMemory
51233KubalionzzaleOrchard (NOI14_orchard)C++14
25 / 25
378 ms12544 KiB
#include <iostream> #include <vector> std::vector< std::vector<int> > g(160); #define int long long int main() { int n, m; std::cin >> n >> m; int cnt = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { int x; std::cin >> x; if (x == 0) { g[i].push_back(-1); } else { g[i].push_back(1); ++cnt; } } } if (cnt == 0) { std::cout << 0; return 0; } int maxSum = 0, lmax, rmax, topmax, bottommax; for (int i = 0; i < n; ++i) { int sum[1000010] = { 0 }; for (int k = i; k < n; ++k) { int last = 0; int curSum = 0; for (int j = 0; j < m; ++j) { sum[j] += g[k][j]; curSum += sum[j]; if (curSum < 0) { last = j + 1; curSum = 0; } else if (curSum > maxSum) { maxSum = curSum; lmax = last; rmax = j; topmax = i; bottommax = k; } } } } // std::cout << topmax << " " << bottommax << " " << lmax << " " << rmax << " " << maxSum << "\n"; int sumOfZero = 0, sumOfOne = 0; for (int i = topmax; i <= bottommax; ++i) { for (int j = lmax; j <= rmax; ++j) { if (g[i][j] == -1) ++sumOfZero; else ++sumOfOne; } } std::cout << cnt - sumOfOne + sumOfZero; }

Compilation message (stderr)

orchard.cpp:8:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
orchard.cpp: In function 'int main()':
orchard.cpp:39:41: warning: 'bottommax' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int maxSum = 0, lmax, rmax, topmax, bottommax;
                                         ^~~~~~~~~
orchard.cpp:39:33: warning: 'topmax' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int maxSum = 0, lmax, rmax, topmax, bottommax;
                                 ^~~~~~
orchard.cpp:39:27: warning: 'rmax' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int maxSum = 0, lmax, rmax, topmax, bottommax;
                           ^~~~
orchard.cpp:39:21: warning: 'lmax' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int maxSum = 0, lmax, rmax, topmax, bottommax;
                     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...