Submission #1605175
Source Code Expand
#include <stdio.h> #define MAX 100001 static int abs(int a) { return a >= 0 ? a : -a; } static int min(int a, int b) { return a <= b ? a : b; } static int n, a[MAX], dp[MAX]; int main(void) { int i; scanf("%d", &n); for (i = 1; i <= n; ++i) scanf("%d", &a[i]); dp[1] = 0; if (n >= 2) dp[2] = dp[1] + abs(a[1] - a[2]); for (i = 3; i <= n; ++i) dp[i] = min( dp[i - 2] + abs(a[i - 2] - a[i]), dp[i - 1] + abs(a[i - 1] - a[i])); printf("%d\n", dp[n]); return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 柱柱柱柱柱 |
User | test20170101 |
Language | C (GCC 5.4.1) |
Score | 100 |
Code Size | 572 Byte |
Status | AC |
Exec Time | 11 ms |
Memory | 896 KB |
Compile Error
./Main.c: In function ‘main’: ./Main.c:12:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.c:14:9: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &a[i]); ^
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 | 128 KB |
sample_02.txt | AC | 0 ms | 128 KB |
sample_03.txt | AC | 1 ms | 128 KB |
subtask1_01.txt | AC | 1 ms | 128 KB |
subtask1_02.txt | AC | 0 ms | 128 KB |
subtask1_03.txt | AC | 1 ms | 128 KB |
subtask1_04.txt | AC | 10 ms | 896 KB |
subtask1_05.txt | AC | 10 ms | 896 KB |
subtask1_06.txt | AC | 11 ms | 896 KB |
subtask1_07.txt | AC | 10 ms | 896 KB |