Submission #490810

# Submission time Handle Problem Language Result Execution time Memory
490810 2021-11-29T10:24:57 Z manizare Bali Sculptures (APIO15_sculpture) C++14
0 / 100
1 ms 552 KB
#include <bits/stdc++.h>

using namespace std;
#define IOS ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define pb push_back
#define all(a) a.begin(),a.end() 
typedef long long ll ;
const int maxn =1e6 + 10;
const int mod = 1e9 + 7 ;
const int maxq = 3000+10;
ll dp[110][110][110];
ll d[maxn];
ll pre[maxn];

int main()
{
	ll n , a , b ;
	cin >> n >> a >> b ;
	for(int i = 1; i <= n ; i++){
		cin >> d[i];
	}
	for(int i = 1 ; i<= n ; i++){
		pre[i] = pre[i-1] + d[i] ;
	}
	for(int i = 1 ; i <= b ; i++){
		for(int l = 1 ; l <= n ; l++){
			for(int r = l ; r <= n ; r++){
				dp[i][l][r] = 1e18;
			}
		}
	}
	for(int i =1 ; i <= n ; i++){
		for(int j = i ; j <= n ; j++){
			dp[1][i][j] = pre[j] - pre[i-1] ;
		}
	}
	for(int x = 2 ; x <= b ; x++){
		for(int l = 1 ; l <= n ; l++){
			for(int r = l ; r <= n ; r++){
				for(int s = 0 ; s < x ; s++){
				if(x==1 && !(l==1 && r==n))continue ;
				if(x==2 && !(l==1 || r==n))continue ;
				if(((l-1)+(n-r)) < (x-1))continue ;
				if((l-1) < (s) || (n-r) < (x-1-s))continue ;
				if(l==1 && r==n){
					dp[x][l][r] = pre[n] ;
					continue;
				}
				if(l==1){
					dp[x][l][r] = min(dp[x][l][r] , pre[r] | dp[x-1-s][r+1][n]); 
					continue ;
				}
				if(r==n){
					dp[x][l][r] = min(dp[x][l][r] , pre[r] - pre[l-1] | dp[s][1][r-1]); 
					continue ;
				}
				dp[x][l][r] = min(dp[x][l][r] , dp[s][1][l-1] | pre[r] - pre[l-1] | dp[x-1-s][r+1][n]);
				}
			}
		}
	}
	ll answer = 1e18 ;
	for(int x = a ; x <= b ; x++){
		for(int l = 1 ; l <= n ; l++){
			for(int r = l ; r <= n ; r++){
				if(x==1 && !(l==1 && r==n))continue ;
				if(x==2 && !(l==1 || r==n))continue ;
				answer = min(answer,dp[x][l][r]) ;
			}
		}
	}
	cout << answer << "\n" ;
    return 0;
}
/*
6 1 3
8 1 2 1 5 4

3 1 3 
1 7 3 
*/

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:54:45: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
   54 |      dp[x][l][r] = min(dp[x][l][r] , pre[r] - pre[l-1] | dp[s][1][r-1]);
      |                                      ~~~~~~~^~~~~~~~~~
sculpture.cpp:57:60: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
   57 |     dp[x][l][r] = min(dp[x][l][r] , dp[s][1][l-1] | pre[r] - pre[l-1] | dp[x-1-s][r+1][n]);
      |                                                     ~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Incorrect 1 ms 552 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 460 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 460 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 460 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 460 KB Output isn't correct
7 Halted 0 ms 0 KB -