Submission #771145
Source Code Expand
#include <iostream> #include <algorithm> #include <cmath> #include <vector> using namespace std; int dp[100000]; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) dp[i] = 1e9; dp[0] = 0; for (int i = 0; i < n; i++) { if (i + 1 < n) dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i] - a[i + 1])); if (i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i] - a[i + 2])); } cout << dp[n - 1] << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 柱柱柱柱柱 |
User | fiord |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 501 Byte |
Status | AC |
Exec Time | 51 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 | 4 ms | 256 KB |
sample_02.txt | AC | 4 ms | 256 KB |
sample_03.txt | AC | 4 ms | 256 KB |
subtask1_01.txt | AC | 4 ms | 256 KB |
subtask1_02.txt | AC | 4 ms | 256 KB |
subtask1_03.txt | AC | 4 ms | 256 KB |
subtask1_04.txt | AC | 49 ms | 1024 KB |
subtask1_05.txt | AC | 49 ms | 1024 KB |
subtask1_06.txt | AC | 48 ms | 1024 KB |
subtask1_07.txt | AC | 51 ms | 1024 KB |