結果

問題 No.595 登山
ユーザー JuRuofan
提出日時 2025-09-05 12:07:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 529 bytes
コンパイル時間 1,895 ms
コンパイル使用メモリ 192,464 KB
実行使用メモリ 7,812 KB
最終ジャッジ日時 2025-09-05 12:08:29
合計ジャッジ時間 3,689 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 5 WA * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |     scanf("%d%lld",&n,&p);
      |     ~~~~~^~~~~~~~~~~~~~~~
main.cpp:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         scanf("%d",&h[i]);
      |         ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2e5+5;
int n;
int h[N];
ll p;
ll f[N][2];
int main(){
    scanf("%d%lld",&n,&p);
    memset(f,0x3f,sizeof(f));
    for(int i=1;i<=n;++i){
        scanf("%d",&h[i]);
    }
    f[1][1]=0;
    f[1][0]=0;
    for(int i=2;i<=n;++i){
        f[i][0]=min(f[i-1][1],min(f[i-1][0],f[i-1][1])+max(0,h[i-1]-h[i]));
        f[i][1]=min(min(f[i-1][0],f[i-1][1])+p+max(0,h[i-1]-h[i]),f[i-1][1]+min(p,1ll*max(0,h[i]-h[i-1])));
    }
    cout<<f[n][1];
    return 0;
}
0