Submission #124516

# Submission time Handle Problem Language Result Execution time Memory
124516 2019-07-03T13:14:21 Z MoNsTeR_CuBe Orchard (NOI14_orchard) C++17
13 / 25
112 ms 33656 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long 

const int INF = 1e18;

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	
	if(n == 1){
		vector< int > v(m+1);
		
		vector< int > dp(m+1);
		
		vector< int > one(m+1);
		
		vector< int > zero(m+1);
		
		
		
		for(int i = 1; i <= m; i++){
			cin >> v[i];
			zero[i] += zero[i-1];
			one[i] += one[i-1];
			
			zero[i] += (v[i] == 0);
			one[i] += (v[i] == 1);
		}
		
		dp[0] = -INF;
		
		int mini = INF;
		
		for(int i = 1; i <= m; i++){
			//cout << "NUMBER " << i << ' ' << "MINI " << mini << endl;
			if(mini + zero[i] < one[i-1] + (v[i] == 0)){
				dp[i] = mini + zero[i];
				if(dp[i]-zero[i-1] <= mini){
					mini = dp[i]-zero[i-1];
				}
			}else{
				dp[i] = one[i-1] + (v[i] == 0);
				if(dp[i]-zero[i-1] <= mini){
					mini = dp[i]-zero[i-1];
				}
			}
			//cout << "DP " << dp[i] << endl;
		}
		int ans = INF;
		
		for(int i = 1; i <= m; i++){
			ans = min(ans, one[m]-one[i] + dp[i]);
		}
		cout << ans << endl;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 888 KB Output is correct
2 Correct 4 ms 888 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 32224 KB Output is correct
2 Correct 108 ms 33656 KB Output is correct
3 Correct 109 ms 33620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -