結果
| 問題 |
No.595 登山
|
| ユーザー |
vjudge1
|
| 提出日時 | 2025-09-05 12:04:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 529 bytes |
| コンパイル時間 | 1,478 ms |
| コンパイル使用メモリ | 162,104 KB |
| 実行使用メモリ | 7,760 KB |
| 最終ジャッジ日時 | 2025-09-05 12:05:03 |
| 合計ジャッジ時間 | 4,202 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#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;
}
vjudge1