結果

問題 No.45 回転寿司
ユーザー vektor_dnchr
提出日時 2016-11-07 03:45:12
言語 Java
(openjdk 23)
結果
AC  
実行時間 186 ms / 5,000 ms
コード長 846 bytes
コンパイル時間 2,614 ms
コンパイル使用メモリ 74,008 KB
実行使用メモリ 42,124 KB
最終ジャッジ日時 2024-12-27 15:43:34
合計ジャッジ時間 9,189 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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