Submission #3888814


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int N;
    int a[100001];
    int dp[100001];

    cin >> N;
    for(int i = 1; i <= N; ++i) cin >> a[i];

    dp[1] = 0;
    dp[2] = abs(a[2] - a[1]);
    for(int i = 3; i <= N; ++i) {
        dp[i] = min(dp[i-1] + abs(a[i]-a[i-1]), dp[i-2] + abs(a[i]-a[i-2]));
    }

    cout << dp[N] << endl;

    return 0;
}

Submission Info

Submission Time
Task C - 柱柱柱柱柱
User heppoko_yuki
Language C++14 (GCC 5.4.1)
Score 100
Code Size 400 Byte
Status
Exec Time 34 ms
Memory 1024 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt
All 100 / 100 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 1 ms 256 KB
sample_02.txt 1 ms 256 KB
sample_03.txt 1 ms 256 KB
subtask1_01.txt 1 ms 256 KB
subtask1_02.txt 1 ms 256 KB
subtask1_03.txt 1 ms 256 KB
subtask1_04.txt 32 ms 1024 KB
subtask1_05.txt 32 ms 1024 KB
subtask1_06.txt 34 ms 1024 KB
subtask1_07.txt 31 ms 1024 KB