# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
321085 | 2020-11-10T22:17:51 Z | fadi57 | Safety (NOI18_safety) | C++14 | 2000 ms | 12644 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mx=200009; const int mod= 998244353; const int inf=2*1e5+9; ll n,h; ll a[mx];ll c[mx]; bool chek(){ for(int i=1;i<n;i++){ if(abs(c[i]-c[i-1])>h){return 0;} } return 1; } int solve(int i,int last){ if(i==n+1){ return 0; }ll ret=inf; for(int j=-1;j<2;j++){ c[i]=j; ll neww=last+j; if(last==0&&j==-1){continue;} ret=min(ret,solve(i+1,last+j)+abs(a[i]-neww)); } return ret; } 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]); }ll ans=inf;for(int i=0;i<=4;i++){ans=min(ans,solve(1,i)+abs(a[0]-i));} cout<<ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 166 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2077 ms | 12644 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |