답안 #162284

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
162284 2019-11-07T12:37:55 Z mosiashvililuka K개의 묶음 (IZhO14_blocks) C++14
0 / 100
78 ms 9840 KB
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f[100009],dp[100009][109],x[100009][109],rm[100009][19],ka[100009],zx,g;
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>b;
	for(c=1; c<=a; c++) cin>>f[c];
	for(c=1; c<=a; c++) rm[c][0]=f[c];
	for(c=1; c<=a; c++){
		for(d=1; d<=18; d++){
			if((1<<d)+c-1>a) break;
			rm[c][d]=max(rm[c][d-1],rm[c+(1<<(d-1))][d-1]);
		}
	}
	ka[0]=0;
	for(c=1; c<=a; c++){
		if((1<<ka[c-1])*2<c) ka[c]=ka[c-1]+1; else ka[c]=ka[c-1];
	}
	for(c=b+1; c<=a; c++) x[c][b+1]=c-1;
	for(c=0; c<=a+1; c++){
		for(d=0; d<=b+1; d++) dp[c][d]=999999999;
	}
	dp[0][0]=0;
	for(c=1; c<=a; c++){
		dp[c][c]=dp[c-1][c-1]+f[c];
		x[c][c]=c-1;
	}
	for(c=2; c<=a; c++){
		for(d=min(b,c-1); d>=1; d--){
			e=x[c][d+1];g=c-e;
			zx=max(rm[e+1][ka[g]],rm[c-(1<<ka[g])+1][ka[g]]);
			for(e=x[c][d+1]; e>=x[c-1][d]; e--){
				if(dp[c][d]>dp[e][d-1]+zx){
			        dp[c][d]=dp[e][d-1]+zx;
			        x[c][d]=e;
				}
				if(zx<f[e]) zx=f[e];
			}
		}
	}
/*	for(c=1; c<=a; c++){
	    for(d=1; d<=min(c,b); d++){
	        cout<<dp[c][d]<<","<<x[c][d]<<" ";
	    }
	    cout<<endl;
	}*/
	cout<<dp[a][b];
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 424 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Incorrect 2 ms 504 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 388 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Incorrect 2 ms 420 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 78 ms 9840 KB Output isn't correct
2 Halted 0 ms 0 KB -