Contest Duration: - (local time) (120 minutes) Back to Home

Submission #3965786

Source Code Expand

Copy
```#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll dp[100000];

int main(){
cin.tie(0);
ios::sync_with_stdio(false);

// input
ll N;
cin >> N;

vector<ll> A(N);
FOR(i, 0, N){
cin >> A.at(i);
}

dp[0] = 0;
dp[1] = abs(A[1] - A[0]);
FOR(i, 2, N){
ll cost0 = dp[i-2] + abs(A[i] - A[i-2]);
ll cost1 = dp[i-1] + abs(A[i] - A[i-1]);

dp[i] = min(cost0, cost1);
}

p(dp[N-1]);

return 0;
}```

#### Submission Info

Submission Time 2019-01-09 14:14:10+0900 C - 柱柱柱柱柱 peroon C++14 (GCC 5.4.1) 100 1034 Byte AC 9 ms 1792 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
 AC × 3
 AC × 10
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt