# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
321212 | 2020-11-11T14:01:41 Z | fadi57 | Safety (NOI18_safety) | C++14 | 2000 ms | 6124 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3180 KB | Output is correct |
2 | Correct | 2 ms | 3180 KB | Output is correct |
3 | Correct | 2 ms | 3180 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 2 ms | 3180 KB | Output is correct |
6 | Correct | 2 ms | 3180 KB | Output is correct |
7 | Correct | 2 ms | 3180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3180 KB | Output is correct |
2 | Correct | 2 ms | 3180 KB | Output is correct |
3 | Correct | 2 ms | 3180 KB | Output is correct |
4 | Correct | 2 ms | 3180 KB | Output is correct |
5 | Correct | 3 ms | 3180 KB | Output is correct |
# | 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 | 1 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 | Correct | 2 ms | 3180 KB | Output is correct |
2 | Correct | 2 ms | 3180 KB | Output is correct |
3 | Correct | 2 ms | 3180 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 2 ms | 3180 KB | Output is correct |
6 | Correct | 2 ms | 3180 KB | Output is correct |
7 | Correct | 2 ms | 3180 KB | Output is correct |
8 | Correct | 2 ms | 3180 KB | Output is correct |
9 | Correct | 2 ms | 3180 KB | Output is correct |
10 | Correct | 2 ms | 3180 KB | Output is correct |
11 | Correct | 2 ms | 3180 KB | Output is correct |
12 | Correct | 3 ms | 3180 KB | Output is correct |
13 | Correct | 10 ms | 3180 KB | Output is correct |
14 | Correct | 5 ms | 3196 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 103 ms | 3180 KB | Output is correct |
17 | Correct | 187 ms | 3300 KB | Output is correct |
18 | Correct | 105 ms | 3300 KB | Output is correct |
19 | Correct | 6 ms | 3180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3180 KB | Output is correct |
2 | Correct | 2 ms | 3180 KB | Output is correct |
3 | Correct | 2 ms | 3180 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 2 ms | 3180 KB | Output is correct |
6 | Correct | 2 ms | 3180 KB | Output is correct |
7 | Correct | 2 ms | 3180 KB | Output is correct |
8 | Correct | 2 ms | 3180 KB | Output is correct |
9 | Correct | 2 ms | 3180 KB | Output is correct |
10 | Correct | 2 ms | 3180 KB | Output is correct |
11 | Correct | 2 ms | 3180 KB | Output is correct |
12 | Correct | 3 ms | 3180 KB | Output is correct |
13 | Correct | 10 ms | 3180 KB | Output is correct |
14 | Correct | 5 ms | 3196 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 103 ms | 3180 KB | Output is correct |
17 | Correct | 187 ms | 3300 KB | Output is correct |
18 | Correct | 105 ms | 3300 KB | Output is correct |
19 | Correct | 6 ms | 3180 KB | Output is correct |
20 | Execution timed out | 2072 ms | 3180 KB | Time limit exceeded |
21 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3180 KB | Output is correct |
2 | Correct | 2 ms | 3180 KB | Output is correct |
3 | Correct | 2 ms | 3180 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 2 ms | 3180 KB | Output is correct |
6 | Correct | 2 ms | 3180 KB | Output is correct |
7 | Correct | 2 ms | 3180 KB | Output is correct |
8 | Correct | 2 ms | 3180 KB | Output is correct |
9 | Correct | 2 ms | 3180 KB | Output is correct |
10 | Correct | 2 ms | 3180 KB | Output is correct |
11 | Correct | 2 ms | 3180 KB | Output is correct |
12 | Correct | 3 ms | 3180 KB | Output is correct |
13 | Correct | 10 ms | 3180 KB | Output is correct |
14 | Correct | 5 ms | 3196 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 103 ms | 3180 KB | Output is correct |
17 | Correct | 187 ms | 3300 KB | Output is correct |
18 | Correct | 105 ms | 3300 KB | Output is correct |
19 | Correct | 6 ms | 3180 KB | Output is correct |
20 | Execution timed out | 2072 ms | 3180 KB | Time limit exceeded |
21 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3180 KB | Output is correct |
2 | Correct | 2 ms | 3180 KB | Output is correct |
3 | Correct | 2 ms | 3180 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 2 ms | 3180 KB | Output is correct |
6 | Correct | 2 ms | 3180 KB | Output is correct |
7 | Correct | 2 ms | 3180 KB | Output is correct |
8 | Correct | 2 ms | 3180 KB | Output is correct |
9 | Correct | 2 ms | 3180 KB | Output is correct |
10 | Correct | 2 ms | 3180 KB | Output is correct |
11 | Correct | 2 ms | 3180 KB | Output is correct |
12 | Correct | 3 ms | 3180 KB | Output is correct |
13 | Runtime error | 7 ms | 6124 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
14 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3180 KB | Output is correct |
2 | Correct | 2 ms | 3180 KB | Output is correct |
3 | Correct | 2 ms | 3180 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 2 ms | 3180 KB | Output is correct |
6 | Correct | 2 ms | 3180 KB | Output is correct |
7 | Correct | 2 ms | 3180 KB | Output is correct |
8 | Correct | 2 ms | 3180 KB | Output is correct |
9 | Correct | 2 ms | 3180 KB | Output is correct |
10 | Correct | 2 ms | 3180 KB | Output is correct |
11 | Correct | 2 ms | 3180 KB | Output is correct |
12 | Correct | 3 ms | 3180 KB | Output is correct |
13 | Runtime error | 7 ms | 6124 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
14 | Halted | 0 ms | 0 KB | - |