結果

問題 No.258 回転寿司(2)
ユーザー GrenacheGrenache
提出日時 2015-07-31 23:25:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 1,235 bytes
コンパイル時間 3,412 ms
コンパイル使用メモリ 76,632 KB
実行使用メモリ 57,340 KB
最終ジャッジ日時 2023-08-06 15:43:14
合計ジャッジ時間 20,971 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 224 ms
56,644 KB
testcase_01 AC 227 ms
56,596 KB
testcase_02 AC 211 ms
56,900 KB
testcase_03 AC 133 ms
55,440 KB
testcase_04 AC 200 ms
54,312 KB
testcase_05 AC 199 ms
56,452 KB
testcase_06 AC 215 ms
56,824 KB
testcase_07 AC 162 ms
54,052 KB
testcase_08 AC 201 ms
56,168 KB
testcase_09 AC 165 ms
55,816 KB
testcase_10 AC 145 ms
55,564 KB
testcase_11 AC 162 ms
55,636 KB
testcase_12 AC 201 ms
56,480 KB
testcase_13 AC 156 ms
55,632 KB
testcase_14 AC 225 ms
56,736 KB
testcase_15 AC 163 ms
55,868 KB
testcase_16 AC 162 ms
55,836 KB
testcase_17 AC 172 ms
55,788 KB
testcase_18 AC 231 ms
57,340 KB
testcase_19 AC 135 ms
55,840 KB
testcase_20 AC 214 ms
56,664 KB
testcase_21 AC 226 ms
56,972 KB
testcase_22 AC 126 ms
55,408 KB
testcase_23 AC 128 ms
55,644 KB
testcase_24 AC 130 ms
55,708 KB
testcase_25 AC 130 ms
53,812 KB
testcase_26 AC 217 ms
56,384 KB
testcase_27 AC 164 ms
55,916 KB
testcase_28 AC 220 ms
56,996 KB
testcase_29 AC 165 ms
56,216 KB
testcase_30 AC 144 ms
55,808 KB
testcase_31 AC 142 ms
55,856 KB
testcase_32 AC 166 ms
55,892 KB
testcase_33 AC 221 ms
56,680 KB
testcase_34 AC 207 ms
56,424 KB
testcase_35 AC 210 ms
56,052 KB
testcase_36 AC 150 ms
56,024 KB
testcase_37 AC 145 ms
55,944 KB
testcase_38 AC 165 ms
56,060 KB
testcase_39 AC 163 ms
55,864 KB
testcase_40 AC 213 ms
57,116 KB
testcase_41 AC 218 ms
56,488 KB
testcase_42 AC 164 ms
55,776 KB
testcase_43 AC 153 ms
56,052 KB
testcase_44 AC 219 ms
57,180 KB
testcase_45 AC 211 ms
56,984 KB
testcase_46 AC 133 ms
55,428 KB
testcase_47 AC 217 ms
56,624 KB
testcase_48 AC 155 ms
55,784 KB
testcase_49 AC 169 ms
56,036 KB
testcase_50 AC 145 ms
55,596 KB
testcase_51 AC 213 ms
56,496 KB
testcase_52 AC 209 ms
56,360 KB
testcase_53 AC 151 ms
56,012 KB
testcase_54 AC 209 ms
56,812 KB
testcase_55 AC 229 ms
57,008 KB
testcase_56 AC 213 ms
56,644 KB
testcase_57 AC 148 ms
56,016 KB
testcase_58 AC 203 ms
56,532 KB
testcase_59 AC 226 ms
56,644 KB
testcase_60 AC 144 ms
55,932 KB
testcase_61 AC 222 ms
56,684 KB
testcase_62 AC 168 ms
55,880 KB
testcase_63 AC 210 ms
56,496 KB
testcase_64 AC 226 ms
56,792 KB
testcase_65 AC 215 ms
56,256 KB
testcase_66 AC 137 ms
55,800 KB
testcase_67 AC 221 ms
56,920 KB
testcase_68 AC 221 ms
56,756 KB
testcase_69 AC 217 ms
57,040 KB
testcase_70 AC 159 ms
55,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;


public class Main_yukicoder258 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] dp = new int[n + 1];
        int[] prev = new int[n + 1];
        boolean[] used = new boolean[n + 1];
        for (int i = 1; i <= n; i++) {
        	int v = sc.nextInt();

        	if (i == 1) {
        		dp[i] = v;
        		prev[i] = 0;
        		used[i] = true;
        	} else {
        		if (dp[i - 1] <= dp[i - 2] + v) {
        			dp[i] = dp[i - 2] + v;
        			prev[i] = i - 2;
        			used[i] = true;
        		} else {
        			dp[i] = dp[i - 1];
        			prev[i] = i - 1;
        		}
        	}
        }

        System.out.println(dp[n]);
        Deque<Integer> st = new ArrayDeque<Integer>();
        for (int i = n; i > 0; ) {
        	if (used[i]) {
        		st.push(i);
        	}
    		i = prev[i];
        }
        boolean flag = false;
        for (int e : st) {
        	if (flag) {
        		System.out.print(" ");
        	}
        	flag = true;
        	System.out.print(e);
        }
        System.out.println("");

        sc.close();
    }
}
0