Submission #577117

# Submission time Handle Problem Language Result Execution time Memory
577117 2022-06-14T06:24:39 Z amunduzbaev Tortoise (CEOI21_tortoise) C++17
0 / 100
7 ms 316 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) || a[i] == 0) 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 += a[i];
		}
		
		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 5 ms 316 KB Output is correct
2 Correct 5 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 7 ms 212 KB Output is correct
6 Correct 4 ms 212 KB Output is correct
7 Correct 5 ms 312 KB Output is correct
8 Correct 5 ms 212 KB Output is correct
9 Correct 6 ms 212 KB Output is correct
10 Correct 4 ms 316 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 5 ms 212 KB Output is correct
13 Correct 6 ms 312 KB Output is correct
14 Correct 6 ms 212 KB Output is correct
15 Correct 4 ms 212 KB Output is correct
16 Incorrect 6 ms 212 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 316 KB Output is correct
2 Correct 5 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 7 ms 212 KB Output is correct
6 Correct 4 ms 212 KB Output is correct
7 Correct 5 ms 312 KB Output is correct
8 Correct 5 ms 212 KB Output is correct
9 Correct 6 ms 212 KB Output is correct
10 Correct 4 ms 316 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 5 ms 212 KB Output is correct
13 Correct 6 ms 312 KB Output is correct
14 Correct 6 ms 212 KB Output is correct
15 Correct 4 ms 212 KB Output is correct
16 Incorrect 6 ms 212 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 316 KB Output is correct
2 Correct 5 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 7 ms 212 KB Output is correct
6 Correct 4 ms 212 KB Output is correct
7 Correct 5 ms 312 KB Output is correct
8 Correct 5 ms 212 KB Output is correct
9 Correct 6 ms 212 KB Output is correct
10 Correct 4 ms 316 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 5 ms 212 KB Output is correct
13 Correct 6 ms 312 KB Output is correct
14 Correct 6 ms 212 KB Output is correct
15 Correct 4 ms 212 KB Output is correct
16 Incorrect 6 ms 212 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 316 KB Output is correct
2 Correct 5 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 7 ms 212 KB Output is correct
6 Correct 4 ms 212 KB Output is correct
7 Correct 5 ms 312 KB Output is correct
8 Correct 5 ms 212 KB Output is correct
9 Correct 6 ms 212 KB Output is correct
10 Correct 4 ms 316 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 5 ms 212 KB Output is correct
13 Correct 6 ms 312 KB Output is correct
14 Correct 6 ms 212 KB Output is correct
15 Correct 4 ms 212 KB Output is correct
16 Incorrect 6 ms 212 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 316 KB Output is correct
2 Correct 5 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 7 ms 212 KB Output is correct
6 Correct 4 ms 212 KB Output is correct
7 Correct 5 ms 312 KB Output is correct
8 Correct 5 ms 212 KB Output is correct
9 Correct 6 ms 212 KB Output is correct
10 Correct 4 ms 316 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 5 ms 212 KB Output is correct
13 Correct 6 ms 312 KB Output is correct
14 Correct 6 ms 212 KB Output is correct
15 Correct 4 ms 212 KB Output is correct
16 Incorrect 6 ms 212 KB Output isn't correct
17 Halted 0 ms 0 KB -