結果

問題 No.45 回転寿司
ユーザー vektor_dnchr
提出日時 2016-11-07 03:45:12
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 104 ms / 5,000 ms
コード長 846 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,977 ms
コンパイル使用メモリ 82,852 KB
実行使用メモリ 45,412 KB
最終ジャッジ日時 2026-06-02 04:01:31
合計ジャッジ時間 6,303 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;

public class Main {
    
    static int N;
    static int[] V = new int[1002];
    static int[] memo = new int[1002];
    
    public static int  rec(int i){
        int ret;
        if(i >= N){ret = 0;}
        else{
            if(memo[i+1] == -1){ memo[i+1] = rec(i+1); }
            if(memo[i+2] == -1){ memo[i+2] = rec(i+2); }
            ret = Math.max(memo[i+1], memo[i+2]+V[i]);
            //System.out.println(i+":"+memo[i+1]+ " " +(memo[i+2]+V[i]));
        }
        
        return ret;
    }
    
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        
        for(int i=0; i<N; i++) V[i] = sc.nextInt();
        Arrays.fill(memo,-1);
        System.out.println(rec(0));
        
        
    }
}
0