Submission #1305987

#TimeUsernameProblemLanguageResultExecution timeMemory
1305987zertinii02Stove (JOI18_stove)C++20
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; #define ios ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr) #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin() + 1, (x).rend() #define fi first #define se second #define yes cout << "YES" << '\n' #define no cout << "NO" << '\n' #define int long long #define veci vector<int> #define skip continue #define sz size() #define pii pair<int,int> const int mod = 1e9 + 7; const int N = 2e6 + 7; const int inf = 1e18; void zertinii() { int n, m; cin >> n >> m; veci a(n + 1); for(int i = 1;i <= n;i++) { cin >> a[i]; } int b[n + 1][n + 1]; for(int i = 1;i <= n;i++) { for(int j = 1;j <= n;j++) { b[i][j] = (a[j] + 1) - a[i]; } } int c[n + 1][m + 1]; for(int i = 1;i <= n;i++) { for(int j = 1;j <= m;j++) { c[i][j] = inf; } } c[0][0] = 0; for(int i = 1;i <= n;i++) { for(int j = 1;j <= m;j++) { for(int k = 0;k < i;k++) { c[i][j] = min(c[i][j], c[k][j - 1] + b[k + 1][i]); } } } int mins = inf; for(int i = 1;i <= m;i++) { mins = min(mins, c[n][i]); } cout << mins; } signed main() { ios; int t = 1; //cin >> t; while(t--) { zertinii(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...