답안 #126035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
126035 2019-07-06T19:54:38 Z streifi 과수원 (NOI14_orchard) C++14
13 / 25
202 ms 16684 KB
#include <iostream>
#include <vector>
using namespace std;

const int INF = 0x3f3f3f3f;

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int N, M;
	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;
			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 = INF;
	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;
				int cntin = (j-i+1)*(mxpos-m+1);
				int in = (cum[j+1][mxpos+1]-cum[j+1][m]-cum[i][mxpos+1]-cum[i][m]);
				int cntout = N*M-cntin;
				int out = cum[N][M]-in;
				//cout << cntin << " " << in << " " << cntout << " " << out << endl;
				best = min(best, cntin - in + cntout + out);
			}
		}
	}
	cout << best/2 << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 16428 KB Output is correct
2 Correct 98 ms 16684 KB Output is correct
3 Correct 98 ms 16684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 3056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 202 ms 7800 KB Output isn't correct
2 Halted 0 ms 0 KB -