답안 #671876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671876 2022-12-14T06:32:04 Z viwlesxq K개의 묶음 (IZhO14_blocks) C++17
0 / 100
82 ms 82508 KB
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;

#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
void freo(str x) {freopen((x + ".in").c_str(), "r", stdin);freopen((x + ".out").c_str(), "w", stdout);}

const int MAXN = 1e5 + 1, MAXK = 1e2;
const ll inf = 1e18 + 7;
vector <vector <ll>> dp(MAXN, vector <ll> (MAXK, inf));
 
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int N, K;
	cin >> N >> K;
	int a[N + 1];
	for (int i = 1; i <= N; i++) cin >> a[i];
	int mx = a[1];
	dp[1][0] = a[1];
	for (int i = 2; i <= N; i++) {
		dp[i][0] = max(a[i], mx);
		mx = max(mx, a[i]);
	}
	int suff_max[N + 2];
	suff_max[N + 1] = 0;
	for (int i = N; i >= 1; i--) suff_max[i] = max(suff_max[i + 1], a[i]);
	for (int i = 1; i <= N; i++) {
		for (int k = 1; k < K; k++) {
			dp[i][k] = min(dp[i - 1][k - 1] + suff_max[i], dp[i - 1][k]);
		}
	}
	cout << dp[N][K - 1];
}

Compilation message

blocks.cpp: In function 'void freo(str)':
blocks.cpp:21:26: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 | void freo(str x) {freopen((x + ".in").c_str(), "r", stdin);freopen((x + ".out").c_str(), "w", stdout);}
      |                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:21:67: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 | void freo(str x) {freopen((x + ".in").c_str(), "r", stdin);freopen((x + ".out").c_str(), "w", stdout);}
      |                                                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 82500 KB Output is correct
2 Correct 82 ms 82380 KB Output is correct
3 Correct 73 ms 82416 KB Output is correct
4 Correct 59 ms 82500 KB Output is correct
5 Correct 61 ms 82380 KB Output is correct
6 Correct 66 ms 82420 KB Output is correct
7 Correct 63 ms 82392 KB Output is correct
8 Correct 65 ms 82380 KB Output is correct
9 Correct 60 ms 82408 KB Output is correct
10 Correct 59 ms 82476 KB Output is correct
11 Incorrect 60 ms 82496 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 82380 KB Output is correct
2 Correct 59 ms 82384 KB Output is correct
3 Correct 60 ms 82508 KB Output is correct
4 Correct 59 ms 82396 KB Output is correct
5 Correct 62 ms 82432 KB Output is correct
6 Correct 60 ms 82508 KB Output is correct
7 Correct 60 ms 82420 KB Output is correct
8 Correct 59 ms 82380 KB Output is correct
9 Correct 63 ms 82508 KB Output is correct
10 Correct 60 ms 82400 KB Output is correct
11 Incorrect 61 ms 82424 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 82500 KB Output is correct
2 Correct 82 ms 82380 KB Output is correct
3 Correct 73 ms 82416 KB Output is correct
4 Correct 59 ms 82500 KB Output is correct
5 Correct 61 ms 82380 KB Output is correct
6 Correct 66 ms 82420 KB Output is correct
7 Correct 63 ms 82392 KB Output is correct
8 Correct 65 ms 82380 KB Output is correct
9 Correct 60 ms 82408 KB Output is correct
10 Correct 59 ms 82476 KB Output is correct
11 Incorrect 60 ms 82496 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 82500 KB Output is correct
2 Correct 82 ms 82380 KB Output is correct
3 Correct 73 ms 82416 KB Output is correct
4 Correct 59 ms 82500 KB Output is correct
5 Correct 61 ms 82380 KB Output is correct
6 Correct 66 ms 82420 KB Output is correct
7 Correct 63 ms 82392 KB Output is correct
8 Correct 65 ms 82380 KB Output is correct
9 Correct 60 ms 82408 KB Output is correct
10 Correct 59 ms 82476 KB Output is correct
11 Incorrect 60 ms 82496 KB Output isn't correct
12 Halted 0 ms 0 KB -