This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
ll mod=(ll)1e9+7;
ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
int n,d,a;
vi arr;
int dp[502][502];
int ans(int idx,int curd)
{
if(idx==n)return 0;
if(dp[idx][curd]!=-1)
return dp[idx][curd];
int e=1e18;
if(arr[idx]<=a)
{
int cur=arr[idx];
for(int i=idx+1;i<n;i++)
{
cur++;
if((arr[i]<cur&&arr[i]<=a)||(cur<=a))
{
e=min(ans(i+1,curd)+(i-idx+1),e);
if(curd)
e=min(ans(i,curd-1)+(i-idx),e);
}
}
}
else e=ans(idx+1,curd);
return dp[idx][curd]=e;
}
void preprocess() {}
void solve()
{
cin>>n>>d>>a;
arr.resize(n);
ent(arr);
memset(dp,-1,sizeof dp);
cout<<ans(0,d)<<endl;
}
signed main()
{
// freopen("meta_game_input.txt","r",stdin);
// freopen("otput.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
preprocess();
//bla();
int t=1;
//cin>>t;
while(t--)
solve();
}
Compilation message (stderr)
prison.cpp: In function 'void solve()':
prison.cpp:14:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | #define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
| ~^~~~~~~~~~~
prison.cpp:50:5: note: in expansion of macro 'ent'
50 | ent(arr);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |