結果
| 問題 |
No.595 登山
|
| ユーザー |
kuuso1
|
| 提出日時 | 2017-11-10 23:36:36 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,460 bytes |
| コンパイル時間 | 1,057 ms |
| コンパイル使用メモリ | 107,008 KB |
| 実行使用メモリ | 43,648 KB |
| 最終ジャッジ日時 | 2024-11-24 15:41:19 |
| 合計ジャッジ時間 | 3,840 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 5 WA * 20 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}
class Sol{
public void Solve(){
int[] R = new int[N];
R[N-1] = N-1;
for(int i=N-2;i>=0;i--){
if(A[i+1] >= A[i]){
R[i] = R[i+1];
} else {
R[i] = i;
}
}
long[] dp = new long[N];
for(int i=0;i<N;i++) dp[i] = long.MaxValue;
dp[0] = 0;
for(int i=0;i<N-1;i++){
dp[i+1] = Math.Min(dp[i+1],dp[i] + Math.Max(0,A[i+1] - A[i]));
if(R[i+1] == N-1){
dp[N-1] = Math.Min(dp[N-1], dp[i] + P);
} else {
dp[R[i+1] + 1] = Math.Min(dp[R[i+1] + 1], dp[i] + P);
}
}
Console.WriteLine(dp[N-1]);
}
int N;
long P;
long[] A;
public Sol(){
var d = ria();
N = d[0]; P = d[1];
A = rla();
}
static String rs(){return Console.ReadLine();}
static int ri(){return int.Parse(Console.ReadLine());}
static long rl(){return long.Parse(Console.ReadLine());}
static double rd(){return double.Parse(Console.ReadLine());}
static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
kuuso1