Submission #577115

# Submission time Handle Problem Language Result Execution time Memory
577115 2022-06-14T06:21:35 Z amunduzbaev Tortoise (CEOI21_tortoise) C++17
0 / 100
6 ms 320 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array

const int N = 40;
int a[N], dp[N][2];
int l[N], r[N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		l[i] = n;
		if(a[i] == -1) l[i] = 0;
		else if(i) l[i] = l[i-1] + 1;
	}
	for(int i=n-1;~i;i--){
		r[i] = n;
		if(a[i] == -1) r[i] = 0;
		else if(i + 1 < n) r[i] = r[i+1] + 1;
	}
	
	int tot = 0;
	for(int mask=0;mask < (1 << n);mask++){
		memset(dp, 1, sizeof dp);
		bool is = 1;
		dp[0][0] = dp[0][1] = 0;
		for(int i=0;i<n && is;i++){
			if(i){
				dp[i][0] = dp[i-1][0] + 1;
				dp[i][1] = dp[i-1][1] + 1;
			}
			if(a[i] == -1){
				dp[i][0] = dp[i][1];
				continue;
			}
			if(!(mask >> i & 1)) continue;
			if(dp[i][0] > 2 * i) is = 0;
			dp[i][1] = dp[i][0];
			dp[i][0] += min(l[i], r[i]) * 2;
		}
		
		if(!is){
			continue;
		}
		
		int res = 0;
		for(int i=0;i<n;i++){
			if(~a[i] && (mask >> i & 1)) res++;
		}
		
		tot = max(tot, res);
	}
	tot *= -1;
	for(int i=0;i<n;i++){
		if(~a[i]) tot += a[i];
	}
	
	cout<<tot<<"\n";
}
 
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Incorrect 6 ms 320 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Incorrect 6 ms 320 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Incorrect 6 ms 320 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Incorrect 6 ms 320 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Incorrect 6 ms 320 KB Output isn't correct
6 Halted 0 ms 0 KB -