結果

問題 No.595 登山
ユーザー kotamanegikotamanegi
提出日時 2017-11-10 22:52:27
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,398 bytes
コンパイル時間 1,089 ms
コンパイル使用メモリ 102,884 KB
実行使用メモリ 5,584 KB
最終ジャッジ日時 2024-05-03 13:03:22
合計ジャッジ時間 3,099 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 WA -
testcase_27 AC 63 ms
5,456 KB
testcase_28 AC 64 ms
5,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)                                                                             
#define seg_size 524288
int main() {
	long long n, k;
	cin >> n >> k;
	long long ans[2] = { 0,LONG_INF };
	vector<long long> wow;
	REP(i, n) {
		long long tmp;
		cin >> tmp;
		wow.push_back(tmp);
	}
	wow.push_back(-1);
	int backing = 0;
	for (int i = 1;i < n+1;++i) {
		if (wow[i - 1] > wow[i]) {
			//backing ~ i-1
			long long a = min(ans[0] + wow[i - 1] - wow[backing], ans[1] + k + wow[i - 1] - wow[backing]);
			long long b = min(ans[0] + k, ans[1] + k);
			backing = i;
			ans[0] = a;
			ans[1] = b;
		}
	}
	cout << min(ans[0], ans[1]) << endl;
	return 0;
}
0