답안 #684557

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684557 2023-01-21T18:14:46 Z pragmatist Stove (JOI18_stove) C++17
50 / 100
252 ms 94592 KB
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
 
#include<bits/stdc++.h>
 
#define sz(v) (int)v.size()
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define nl "\n"
 
using namespace std;
using pii = pair<int, int>;
 
const int N = (int)5e3 + 7; // make sure this is right
const int M = (int)1e6 + 7;
const int inf = (int)1e9 + 7;
const ll INF = (ll)3e18 + 7; 
const ll MOD = (ll)998244353; // make sure this is right
 
bool bit(int x, int i) {
	return x >> i & 1;
}
 
pii dir[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int n, k, a[N], dp[N][N], opt[N][N];
 
void solve() {
	cin >> n >> k;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		opt[i][0] = 1;                        
		dp[i][0] = inf;
	}
	for(int j = 1; j <= k; ++j) opt[n + 1][j] = n;
	for(int j = 1; j <= k; ++j) {
		for(int i = n; i >= 1; --i) {
			dp[i][j] = inf;
			int idx = -1;
			for(int l = opt[i][j - 1]; l <= min(i, opt[i + 1][j]); ++l) {
				int cur = dp[l - 1][j - 1] + (a[i] - a[l] + 1);
				if(cur < dp[i][j]) {
					dp[i][j] = cur;
					idx = l;
				} 		
			}
			opt[i][j] = idx;
			assert(idx != -1);
		}
	}
	cout << dp[n][k];
}
 
signed main() {	
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; ++i) {
	 	//cout << "Case #" << i << ": ";
		solve();
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 28 ms 24732 KB Output is correct
11 Correct 29 ms 26860 KB Output is correct
12 Correct 108 ms 47936 KB Output is correct
13 Correct 176 ms 71420 KB Output is correct
14 Correct 251 ms 92540 KB Output is correct
15 Correct 252 ms 94592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 28 ms 24732 KB Output is correct
11 Correct 29 ms 26860 KB Output is correct
12 Correct 108 ms 47936 KB Output is correct
13 Correct 176 ms 71420 KB Output is correct
14 Correct 251 ms 92540 KB Output is correct
15 Correct 252 ms 94592 KB Output is correct
16 Runtime error 135 ms 82768 KB Execution killed with signal 11
17 Halted 0 ms 0 KB -