提出 #772581
ソースコード 拡げる
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include<string>
#include <math.h>
#include<vector>
#include <math.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[100001];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long b[100001] = {0};
b[n - 1] = 0;
b[n - 2] = abs(a[n - 1] - a[n - 2]);
for (int i = n - 3; i >= 0; i--) {
int r = abs(a[i] - a[i + 1]);
int l = abs(a[i] - a[i + 2]);
if (r<l){
b[i] = b[i + 1] + r;
}
else {
b[i] = b[i + 2] + l;
}
}
cout<< b[0] << endl;
return 0;
}
提出情報
ジャッジ結果
| セット名 | Sample | All | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 100 | ||||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| 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 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| sample_01.txt | AC | 5 ms | 1024 KiB |
| sample_02.txt | WA | 5 ms | 1024 KiB |
| sample_03.txt | AC | 5 ms | 1024 KiB |
| subtask1_01.txt | AC | 5 ms | 1024 KiB |
| subtask1_02.txt | AC | 5 ms | 1024 KiB |
| subtask1_03.txt | AC | 5 ms | 1024 KiB |
| subtask1_04.txt | WA | 57 ms | 1408 KiB |
| subtask1_05.txt | WA | 57 ms | 1408 KiB |
| subtask1_06.txt | WA | 57 ms | 1408 KiB |
| subtask1_07.txt | WA | 57 ms | 1408 KiB |