結果

問題 No.45 回転寿司
ユーザー vektor_dnchrvektor_dnchr
提出日時 2016-11-07 03:41:17
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 846 bytes
コンパイル時間 2,387 ms
コンパイル使用メモリ 75,020 KB
実行使用メモリ 57,444 KB
最終ジャッジ日時 2024-05-03 22:31:44
合計ジャッジ時間 8,875 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 169 ms
41,572 KB
testcase_01 AC 166 ms
42,052 KB
testcase_02 AC 186 ms
41,872 KB
testcase_03 AC 185 ms
41,896 KB
testcase_04 AC 180 ms
41,912 KB
testcase_05 AC 143 ms
41,096 KB
testcase_06 AC 172 ms
41,684 KB
testcase_07 AC 184 ms
41,992 KB
testcase_08 AC 161 ms
41,516 KB
testcase_09 AC 184 ms
42,196 KB
testcase_10 AC 174 ms
41,508 KB
testcase_11 AC 156 ms
41,236 KB
testcase_12 AC 181 ms
42,392 KB
testcase_13 AC 135 ms
41,168 KB
testcase_14 AC 134 ms
41,044 KB
testcase_15 AC 158 ms
41,416 KB
testcase_16 AC 148 ms
41,392 KB
testcase_17 AC 172 ms
41,676 KB
testcase_18 AC 161 ms
42,008 KB
testcase_19 AC 178 ms
42,308 KB
testcase_20 AC 119 ms
40,068 KB
testcase_21 AC 135 ms
41,668 KB
testcase_22 AC 112 ms
39,868 KB
testcase_23 AC 123 ms
41,104 KB
testcase_24 AC 129 ms
41,520 KB
testcase_25 AC 116 ms
40,536 KB
testcase_26 AC 168 ms
41,828 KB
testcase_27 AC 177 ms
41,840 KB
testcase_28 AC 181 ms
42,076 KB
testcase_29 AC 177 ms
41,652 KB
testcase_30 AC 178 ms
42,012 KB
testcase_31 AC 130 ms
40,968 KB
testcase_32 AC 123 ms
41,004 KB
testcase_33 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    
    static int N;
    static int[] V = new int[1000];
    static int[] memo = new int[1000];
    
    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