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
Task C - 柱柱柱柱柱
User peroon
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1034 Byte
Status AC
Exec Time 9 ms
Memory 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
All sample_01.txt, sample_02.txt, sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask1_01.txt AC 1 ms 256 KB
subtask1_02.txt AC 1 ms 256 KB
subtask1_03.txt AC 1 ms 256 KB
subtask1_04.txt AC 9 ms 1792 KB
subtask1_05.txt AC 9 ms 1792 KB
subtask1_06.txt AC 9 ms 1792 KB
subtask1_07.txt AC 9 ms 1792 KB