# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
705511 | BidoTeima | 과수원 (NOI14_orchard) | C++17 | 129 ms | 17896 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.
/*
ID: BidoTeima
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void moo(string filename);
void ACPLS(string str = "")
{
if(str=="NOF")return;
if(str.size() && str != "IIOT")
moo(str);
else if(str != "IIOT"){
#ifndef ONLINE_JUDGE
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
#endif
}
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void moo(string fileName){
freopen((fileName+".in").c_str(),"r",stdin);
freopen((fileName+".out").c_str(),"w",stdout);
}
#define tc \
int tttttt/*,subtask*/; \
cin >> tttttt/* >> subtask*/; \
while (tttttt--)/*end
*/
int main()
{
ACPLS("IIOT");
int n,m;
cin>>n>>m;
int a[n+1][m+1]={0};
int total = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
char ch;
cin>>ch;
a[i][j]=ch-'0';
total += a[i][j];
}
}
int colsum[n + 1][m + 1]={0};
for(int j = 1; j <= m; j++){
for(int i = 1; i <= n; i++){
colsum[i][j] = colsum[i - 1][j] + a[i][j];
}
}
int ans = 1e9;
for(int a = 1; a <= n; a++){
for(int x = a; x <= n; x++){
int mn = 0;
int cursum = 0;
for(int i = 1; i <= m; i++){
cursum += colsum[x][i] - colsum[a - 1][i];
ans = min(ans, total + i * (x - a + 1) - 2 * cursum + mn);
mn = min(mn, 2 * cursum - i * (x - a + 1));
}
}
}
cout << ans << '\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... |