Submission #321212

#TimeUsernameProblemLanguageResultExecution timeMemory
321212fadi57Safety (NOI18_safety)C++14
13 / 100
2072 ms6124 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mx=600; const int mod= 998244353; const ll inf=2*1e16+9; ll n,h; ll a[mx];ll c[mx]; ll dp[mx][mx]; int main() { cin>>n>>h; ll sum=0;ll mxx=500; for(int i=0;i<n;i++){ cin>>a[i]; mxx=max(mxx,a[i]); } if(h>mxx){cout<<0;return 0;} memset(dp,inf,sizeof(dp)); for(int i=0;i<=mxx;i++){ dp[0][i]=abs(a[0]-i); } for(int i=1;i<n;i++){ for(int j=0;j<=mxx;j++){ for(int jj=j;jj<=j+h;jj++){ dp[i][j]=min(dp[i][j],dp[i-1][jj]+abs(a[i]-j)); } for(int jj=j-1;jj>=(j-h)&&jj>=0;jj--){ dp[i][j]=min(dp[i][j],dp[i-1][jj]+abs(a[i]-j)); } } } ll ans=inf; for(int i=0;i<=mxx;i++){ans=min(ans,dp[n-1][i]);}cout<<ans; }

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:19:11: warning: overflow in conversion from 'll' {aka 'long long int'} to 'int' changes value from '20000000000000008' to '-545128440' [-Woverflow]
   19 | memset(dp,inf,sizeof(dp));
      |           ^~~
safety.cpp:12:4: warning: unused variable 'sum' [-Wunused-variable]
   12 | ll sum=0;ll mxx=500;
      |    ^~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...