Submission #205681

# Submission time Handle Problem Language Result Execution time Memory
205681 2020-02-29T13:18:19 Z ZwariowanyMarcin Orchard (NOI14_orchard) C++14
0 / 25
377 ms 6264 KB
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep2(i, j, n) for (LL i = j; i <= n; ++i)
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define boost cin.tie(0);ios_base::sync_with_stdio(0);
#define vi vector <int>

using namespace std;

const int nax = 5005;

int n, m;
char s[nax];
int a[155][nax];
int g[155][nax];
LL f[nax];
LL best = 1e18;
int ones;

int main() {	
	scanf ("%d%d", &n, &m);
	
	rep(i, 1, n) {
		scanf ("%s", s + 1);
		rep(j, 1, m)
			a[i][j] = (int) s[j] - '0';
	}
	
	rep(i, 1, n) rep(j, 1, m) {
		g[i][j] = (a[i][j] == 1) + g[i - 1][j];
		ones += (a[i][j] == 1);
	}
	
	rep(i, 1, n)
		rep(j, i, n) {
			rep(x, 1, m) f[x] = g[j][x] - g[i - 1][x];
			LL opt = 1e18;
			int h = j - i + 1;
			rep(x, 1, m) f[x] += f[x - 1];
			
			rep(x, 1, m) {
				opt = min(opt, 2 * f[x - 1] - h * (x - 1));
				best = min(best, ones + (h * x) - 2 * f[x] + opt);
			}
			
		}
	printf ("%lld\n", best);
			
	
	return 0;
}

Compilation message

orchard.cpp: In function 'int main()':
orchard.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d", &n, &m);
  ~~~~~~^~~~~~~~~~~~~~~~
orchard.cpp:32:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%s", s + 1);
   ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 636 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 377 ms 6264 KB Output isn't correct
2 Halted 0 ms 0 KB -