답안 #1101402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101402 2024-10-16T08:11:44 Z quocthang K개의 묶음 (IZhO14_blocks) C++14
0 / 100
3 ms 6400 KB
#include <bits/stdc++.h>
#define base 31
#define fi first
#define endl "\n"
#define se second
#define NAME "FILE"
#define ll long long
//#define int long long
#define mod 1000000007
#define pii pair<int,int>
#define bit(mask,i) (mask&(1<<i))
#define lcm(a,b) ((a*b)/__gcd(a,b))
#define turn_on(mask,i) (mask|(1<<i))
#define turn_off(mask,i) (mask^(1<<i))

template <class T1, class T2>
bool maximize(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;}

template <class T1, class T2>
bool minimize(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;}

template <class T1, class T2>
void add(T1 &a, T2 b){a += b; if (a >= mod) a -= mod;}

template <class T1, class T2>
void sub(T1 &a, T2 b){a -= b; if (a < 0) a += mod;}

using namespace std;
int n,k,dp[1010][1010],a[100010]; 
int mx[100010][20];
int get(int l,int r){
	int k=__lg(r-l+1);
	return max(mx[l][k],mx[r-(1<<k)+1][k]);
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	if (fopen(NAME".inp","r")){
		freopen(NAME".inp","r",stdin);
		freopen(NAME".out","w",stdout);
	}
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i],mx[i][0]=a[i];
	for(int j=1;(1<<j)<=n;j++){
		for(int i=1;i+(1<<j)-1<=n;i++){
			mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
		}
	}
	memset(dp,0x3f,sizeof dp);
	dp[0][0]=0;
	for(int j=1;j<=k;j++){
		for(int i=1;i<=n;i++){
			for(int k=1;k<=j;k++){
				minimize(dp[i][j],dp[k-1][j-1]+get(k,i));
			}
		}
	}
	cout<<dp[n][k];
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:39:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   freopen(NAME".inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:40:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   freopen(NAME".out","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6224 KB Output is correct
2 Correct 2 ms 6224 KB Output is correct
3 Correct 2 ms 6224 KB Output is correct
4 Correct 2 ms 6224 KB Output is correct
5 Correct 2 ms 6400 KB Output is correct
6 Correct 2 ms 6224 KB Output is correct
7 Correct 2 ms 6224 KB Output is correct
8 Incorrect 2 ms 6224 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6224 KB Output is correct
2 Correct 3 ms 6224 KB Output is correct
3 Correct 2 ms 6224 KB Output is correct
4 Correct 2 ms 6224 KB Output is correct
5 Correct 3 ms 6224 KB Output is correct
6 Correct 2 ms 6224 KB Output is correct
7 Correct 2 ms 6392 KB Output is correct
8 Incorrect 2 ms 6224 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6224 KB Output is correct
2 Correct 2 ms 6224 KB Output is correct
3 Correct 2 ms 6224 KB Output is correct
4 Correct 2 ms 6224 KB Output is correct
5 Correct 2 ms 6400 KB Output is correct
6 Correct 2 ms 6224 KB Output is correct
7 Correct 2 ms 6224 KB Output is correct
8 Incorrect 2 ms 6224 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6224 KB Output is correct
2 Correct 2 ms 6224 KB Output is correct
3 Correct 2 ms 6224 KB Output is correct
4 Correct 2 ms 6224 KB Output is correct
5 Correct 2 ms 6400 KB Output is correct
6 Correct 2 ms 6224 KB Output is correct
7 Correct 2 ms 6224 KB Output is correct
8 Incorrect 2 ms 6224 KB Output isn't correct
9 Halted 0 ms 0 KB -