結果

問題 No.45 回転寿司
ユーザー E. Gordon
提出日時 2019-04-07 19:06:40
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 700 bytes
コンパイル時間 2,028 ms
コンパイル使用メモリ 56,416 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 20:26:13
合計ジャッジ時間 2,232 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |         scanf("%d", &v[i]);
      |         ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
int memo[1000][2] = {0};

int ssh(int *d, int n)
{
    if(n < 0) return 0;
    if(n >= 1){
        if(n >= 2){
            if(memo[n-2][0] == 0){
                memo[n-2][1] = ssh(d, n-2);
                memo[n-2][0] = 1;
            }
        }
        if(memo[n-1][0] == 0){
            memo[n-1][1] = ssh(d, n-1);
            memo[n-1][0] = 1;
        }
    }
    return max((n >= 2 ? memo[n-2][1] : 0) + d[n],
               (n >= 1 ? memo[n-1][1] : 0)       );
}

int main()
{
    int n, v[1000] = {0};
    cin >> n;
    for(int i = 0; i < n; i++){
        scanf("%d", &v[i]);
    }
    cout << ssh(v, n-1) << endl;
    return 0;
}
0