結果

問題 No.45 回転寿司
ユーザー Bantako
提出日時 2017-07-09 08:56:18
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 308 bytes
コンパイル時間 1,963 ms
コンパイル使用メモリ 33,352 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 16:37:50
合計ジャッジ時間 1,670 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
    7 | main(){
      | ^~~~
main.cpp: In function ‘int main()’:
main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%d",&V[i]);
      |         ~~~~~^~~~~~~~~~~~

ソースコード

diff #

//ナップザック亜種?
#include<stdio.h>
#include<algorithm>
int N;
int V[1000];
int dp[1002];
main(){
    scanf("%d",&N);
    for(int i = 0;i < N;i++){
        scanf("%d",&V[i]);
    }
    for(int i = N-1;i >= 0;i--){
        dp[i] = std::max(dp[i+1],dp[i+2]+V[i]);
    }
    printf("%d\n",dp[0]);
}
0