Submission #345177

# Submission time Handle Problem Language Result Execution time Memory
345177 2021-01-07T06:00:16 Z mansur K blocks (IZhO14_blocks) C++14
0 / 100
1 ms 364 KB
#include<bits/stdc++.h>
using namespace std;
 
#define all(a) a.begin(),a.end()
#define ll long long
#define pb push_back
#define nl '\n'
#define popb pop_back()
#define sz size()
#define ld long double
#define ull unsigned long long
#define F first
#define S second
#define fix fixed<<setprecision
#define pii pair<int,int>
#define E exit (0)
#define int long long
const int inf=1e9;
int c[100001],mn=inf,n;
void r(int pos,int k,int sum=0,int mx=0) {
	if (pos==n+1&&k>0) {
		return;
	}
	if (k==0&&pos==n+1) {
		mn=min(mn,sum);
		return;
	}
	if (k<0) {
		return;
	}
	r(pos+1,k-1,sum+c[pos],c[pos]);
	r(pos+1,k,sum-mx+max(mx,c[pos]),max(mx,c[pos]));
}
signed main() {
	//freopen("planting.in","r",stdin);
	//freopen("planting.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int k;
	cin>>n>>k;
	int s[n+2];
	s[n+1]=0;
	for (int i=1;i<=n;i++) {
		cin>>c[i];
	}
	for (int i=n;i>=1;i--) {
		s[i]=max(s[i+1],c[i]);
	}
	if (k<=5) {
		int mn=inf;
    	for (int i=1,mx1=0;i<=n;i++) {
    		mx1=max(mx1,c[i]);
    		if (k>=2) {
    			for (int j=i+1,mx2=0;j<=n;j++) {
    				mx2=max(mx2,c[j]);
    				if (k>=3) {
    					for (int d=j+1,mx3=0;d<=n;d++) {
    						mx3=max(mx3,c[d]);
    						if (k>=4) {
    							for (int f=d+1,mx4=0;f<=n;f++) {
    								mx4=max(mx4,c[f]);
    								mn=min(mn,mx4+mx3+mx2+mx1+s[f+1]);		
    							}
    						}else {
    							mn=min(mn,mx3+mx2+mx1+s[d+1]);	
    						}
    					}
    				}else {
    					mn=min(mn,mx1+mx2+s[j+1]);
    				}
    			}
    		}else {
    			mn=min(mn,mx1+s[i+1]);	
    		}
    	}
    	cout<<mn;
    	return 0;
    }
	r(1,k);         
	cout<<mn;
}         
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Incorrect 1 ms 364 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Incorrect 1 ms 364 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Incorrect 1 ms 364 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Incorrect 1 ms 364 KB Output isn't correct
12 Halted 0 ms 0 KB -