# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
124529 | johutha | Orchard (NOI14_orchard) | C++14 | 278 ms | 15992 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>
#define int int64_t
using namespace std;
struct orchard
{
vector<vector<int>> orchard;
int n, m;
int calc()
{
for (int i = 0; i < n; i++)
{
int currsum = 0;
int mmin = 0;
int mp = -1;
int mdiff = 0;
int msp = 0;
int me = 0;
for (int j = 0; j < m; j++)
{
currsum += (orchard[i][j]) - (!orchard[i][j]);
if (currsum < mmin)
{
mmin = currsum;
mp = j;
}
if (currsum - mmin > mdiff)
{
msp = mp;
mdiff = currsum - mmin;
me = j;
}
}
currsum = 0;
for (int j = 0; j < m; j++)
{
if (j <= msp || j > me) currsum += (orchard[i][j]);
else currsum += (!orchard[i][j]);
}
return currsum;
}
}
};
signed main()
{
int n, m;
cin >> n >> m;
orchard orch;
orch.n = n;
orch.m = m;
orch.orchard.resize(n, vector<int>(m));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> orch.orchard[i][j];
}
}
cout << orch.calc() << "\n";
}
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... |