# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
51233 | Kubalionzzale | Orchard (NOI14_orchard) | C++14 | 378 ms | 12544 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |