Submission #2122560
Source Code Expand
#include <math.h> #include <ctype.h> #include <bits/stdc++.h> using namespace std; #define FOR(i, a, n) for (int i = a; i < n; i++) #define REP(i, n) for(int i = 0; i < n; i++) int main(){ int n; cin >> n; int A[n]; REP(i, n) cin >> A[i]; int dp[n + 1]; dp[0] = 0; dp[1] = abs(A[1] - A[0]); int a, b; for(int i = 2; i < n; i++){ a = dp[i - 2] + abs(A[i - 2] - A[i]); b = dp[i - 1] + abs(A[i - 1] - A[i]); dp[i] = min(a, b); } cout << dp[n - 1] << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 柱柱柱柱柱 |
User | tokizo |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 568 Byte |
Status | AC |
Exec Time | 32 ms |
Memory | 1024 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 100 / 100 | ||||
Status |
|
|
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 | 31 ms | 1024 KB |
subtask1_05.txt | AC | 32 ms | 1024 KB |
subtask1_06.txt | AC | 31 ms | 1024 KB |
subtask1_07.txt | AC | 31 ms | 1024 KB |