結果

問題 No.45 回転寿司
ユーザー vektor_dnchrvektor_dnchr
提出日時 2016-11-07 03:45:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 185 ms / 5,000 ms
コード長 846 bytes
コンパイル時間 3,652 ms
コンパイル使用メモリ 71,732 KB
実行使用メモリ 56,656 KB
最終ジャッジ日時 2023-08-27 15:16:17
合計ジャッジ時間 10,516 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 160 ms
55,776 KB
testcase_01 AC 173 ms
55,888 KB
testcase_02 AC 183 ms
56,312 KB
testcase_03 AC 183 ms
56,460 KB
testcase_04 AC 182 ms
55,636 KB
testcase_05 AC 134 ms
56,104 KB
testcase_06 AC 165 ms
56,340 KB
testcase_07 AC 182 ms
56,020 KB
testcase_08 AC 160 ms
56,204 KB
testcase_09 AC 183 ms
56,164 KB
testcase_10 AC 173 ms
56,656 KB
testcase_11 AC 142 ms
56,136 KB
testcase_12 AC 183 ms
56,212 KB
testcase_13 AC 132 ms
55,948 KB
testcase_14 AC 135 ms
55,744 KB
testcase_15 AC 166 ms
56,480 KB
testcase_16 AC 152 ms
54,140 KB
testcase_17 AC 181 ms
56,068 KB
testcase_18 AC 156 ms
55,860 KB
testcase_19 AC 185 ms
55,712 KB
testcase_20 AC 134 ms
55,984 KB
testcase_21 AC 136 ms
55,984 KB
testcase_22 AC 125 ms
55,700 KB
testcase_23 AC 127 ms
55,772 KB
testcase_24 AC 128 ms
56,360 KB
testcase_25 AC 126 ms
55,960 KB
testcase_26 AC 172 ms
56,208 KB
testcase_27 AC 184 ms
55,636 KB
testcase_28 AC 173 ms
56,036 KB
testcase_29 AC 183 ms
55,728 KB
testcase_30 AC 185 ms
56,188 KB
testcase_31 AC 126 ms
55,796 KB
testcase_32 AC 124 ms
55,612 KB
testcase_33 AC 176 ms
56,188 KB
権限があれば一括ダウンロードができます

ソースコード

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