답안 #125994

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125994 2019-07-06T17:01:41 Z streifi 과수원 (NOI14_orchard) C++14
13 / 25
82 ms 10236 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<int> v(M), cum(M+1, 0);
	for (int m = 0; m < M; ++m) {
		cin >> v[m];
		if (v[m] == 0) v[m] = -1;
		cum[m+1] = cum[m]+v[m];
		//cout << cum[m+1] << endl; 
	}
	int mxpos = M-1;
	int best = INF;
	for (int m = M-1; m >= 0; --m) {
		if (cum[m+1] > cum[mxpos+1])
			mxpos = m;
		int cur1 = (M-mxpos-1)+(cum[M]-cum[mxpos+1]);
		int cur2 = (mxpos-m+1)-(cum[mxpos+1]-cum[m]);
		int cur3 = m + cum[m];
		//cout << cur1 << " " << cur2 << " " << cur3 << endl;
		best = min(best, cur1+cur2+cur3);
	}
	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 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 8184 KB Output is correct
2 Correct 82 ms 10076 KB Output is correct
3 Correct 82 ms 10236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 1148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -