이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
using namespace std;
typedef long long ll;
vector<vector<ll > > table;
int main()
{
ll n, m;
ll counter=0;
ll ans = LLONG_MAX;
bool gay;
cin >> n >> m;
table.assign(n+1, vector<ll> (m+1, 0));
for (ll i=1; i<=n; ++i)
{
for (ll j=1; j<=m; ++j)
{
cin >> gay;
if (gay) {counter++; table[i][j] = -1;}
else {table[i][j] = 1;}
table[i][j] += table[i-1][j] + table[i][j-1] - table[i-1][j-1];
}
}
for (ll i=1; i<=n; ++i)
{
ll best[n+1];
for (ll x=1; x<=n; ++x) best[x]=-LLONG_MAX;
for (ll j=1; j<=m; ++j)
{
ll maxx = 0;
for (ll k=1; k<=i; ++k)
{
if (j!=1) best[k]-=table[k-1][j-1] - table[k-1][j];
best[k] = max(best[k], table[k-1][j] + table[i][j-1]-table[k-1][j-1] );
maxx=max(best[k],maxx);
}
ans = min(ans, table[i][j]-maxx);
}
}
cout << counter + ans << endl;
return 0;
}
# | 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... |