Submission #13650516


Source Code Expand

Copy
#include <iostream>
#include <vector>


#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;

signed main() {
    FAST_IO;

    int n;
    cin >> n;
    int jumps[n];
    vector<int> dp(n, 0); // dp[i] : Minimum cost for the frog to reach position i.
    for (int i = 0; i < n; i++) cin >> jumps[i];
    dp[1] = abs(jumps[1] - jumps[0]); // Base value
    for (int i = 2; i < n; i++)
        dp[i] = min(abs(jumps[i] - jumps[i - 1]) + dp[i - 1], abs(jumps[i] - jumps[i - 2]) + dp[i - 2]);
    cout << dp[n - 1];
    return 0;
}

Submission Info

Submission Time
Task A - Frog 1
User arujbansal
Language C++14 (GCC 5.4.1)
Score 100
Code Size 582 Byte
Status AC
Exec Time 9 ms
Memory 1024 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 11
Set Name Test Cases
All 0_00, 0_01, 0_02, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07
Case Name Status Exec Time Memory
0_00 AC 1 ms 256 KB
0_01 AC 1 ms 256 KB
0_02 AC 1 ms 256 KB
1_00 AC 1 ms 256 KB
1_01 AC 1 ms 256 KB
1_02 AC 8 ms 1024 KB
1_03 AC 9 ms 1024 KB
1_04 AC 9 ms 1024 KB
1_05 AC 9 ms 1024 KB
1_06 AC 9 ms 1024 KB
1_07 AC 9 ms 1024 KB