Submission #321205

# Submission time Handle Problem Language Result Execution time Memory
321205 2020-11-11T13:55:42 Z fadi57 Safety (NOI18_safety) C++14
0 / 100
7 ms 6124 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mx=600;
const int mod= 998244353;
const int 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=0;
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<=500;i++){ans=min(ans,dp[n-1][i]);}cout<<ans;
}

Compilation message

safety.cpp:6:21: warning: overflow in conversion from 'double' to 'int' changes value from '2.0000000000000008e+16' to '2147483647' [-Woverflow]
    6 | const int inf=2*1e16+9;
      |               ~~~~~~^~
safety.cpp: In function 'int main()':
safety.cpp:12:4: warning: unused variable 'sum' [-Wunused-variable]
   12 | ll sum=0;ll mxx=0;
      |    ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 6124 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3180 KB Output isn't correct
2 Halted 0 ms 0 KB -