Submission #936156

#TimeUsernameProblemLanguageResultExecution timeMemory
936156shoryu386The short shank; Redemption (BOI21_prison)C++17
15 / 100
2045 ms251984 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n, d, t; #define MAX 4007 int arr[MAX], dp[MAX][MAX]; int memo[MAX][MAX]; int cost(int l, int r){ //optimised easily to n^2 if (memo[l][r] != -1) return memo[l][r]; int ans = 0; if (arr[l] <= t) ans++; int carry = arr[l] + 1; for (int x = l+1; x <= r; x++){ int val = min(arr[x], carry); if (val <= t) ans++; carry = min(carry, arr[x]); carry += 1; } return memo[l][r] = ans; } main(){ cin >> n >> d >> t; for (int x = 0; x < n; x++) cin >> arr[x]; memset(memo, -1, sizeof(memo)); memset(dp, 63, sizeof(dp)); for (int x = 0; x < n; x++){ dp[x][1] = min(dp[x][1], cost(0, x)); for (int z = 1; z <= n; z++){ for (int y = 0; y < x; y++){ dp[x][z] = min(dp[x][z], dp[y][z-1] + cost(y+1, x)); } } } cout << dp[n-1][d+1]; }

Compilation message (stderr)

prison.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   32 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...