Submission #126050

# Submission time Handle Problem Language Result Execution time Memory
126050 2019-07-06T21:04:46 Z streifi Orchard (NOI14_orchard) C++14
17 / 25
168 ms 31716 KB
#include <iostream>
#include <vector>
using namespace std;

//const int INF = 0x3f3f3f3f;
#define int long long

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int N, M, cnt = 0;
	cin >> N >> M;
	
	vector<vector<int>> v(N, vector<int>(M)), cum(N+1, vector<int>(M+1, 0));
	for (int n = 0; n < N; ++n) {
		for (int m = 0; m < M; ++m) {
			cin >> v[n][m];
			if (v[n][m] == 0)
				v[n][m] = -1;
			else
				++cnt;
			cum[n+1][m+1] = cum[n+1][m]+cum[n][m+1]-cum[n][m]+v[n][m];
			//cout << cum[m+1] << endl; 
		}
	}
	
	/*for (int n = 1; n <= N; ++n) {
		for (int m = 1; m <= M; ++m) {
			cout << cum[n][m] << " ";
		}
		cout << endl;
	}*/
	
	int best = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = i; j < N; ++j) {
			int mxpos = M-1;
			for (int m = M-1; m >= 0; --m) {
				if (cum[j+1][m+1] > cum[j+1][mxpos+1]) mxpos = m;
				best = max(best, cum[j+1][mxpos+1]-cum[j+1][m]-cum[i][mxpos+1]+cum[i][m]);
			}
		}
	}
	cout << (cnt-best) << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 31716 KB Output is correct
2 Correct 115 ms 31704 KB Output is correct
3 Correct 113 ms 31712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 5096 KB Output is correct
2 Incorrect 22 ms 5100 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 8 ms 760 KB Output is correct
3 Correct 8 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 168 ms 12224 KB Output isn't correct
2 Halted 0 ms 0 KB -