結果

問題 No.258 回転寿司(2)
ユーザー ぴろずぴろず
提出日時 2015-07-31 22:53:21
言語 Java19
(openjdk 21)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 967 bytes
コンパイル時間 4,233 ms
コンパイル使用メモリ 74,764 KB
実行使用メモリ 57,960 KB
最終ジャッジ日時 2023-08-06 15:40:57
合計ジャッジ時間 18,513 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 193 ms
57,960 KB
testcase_01 AC 192 ms
55,996 KB
testcase_02 AC 187 ms
55,860 KB
testcase_03 AC 134 ms
55,408 KB
testcase_04 AC 181 ms
56,296 KB
testcase_05 AC 186 ms
55,948 KB
testcase_06 AC 189 ms
56,500 KB
testcase_07 AC 152 ms
56,216 KB
testcase_08 AC 186 ms
55,488 KB
testcase_09 AC 158 ms
55,760 KB
testcase_10 AC 137 ms
55,428 KB
testcase_11 AC 155 ms
55,700 KB
testcase_12 AC 166 ms
55,760 KB
testcase_13 AC 147 ms
55,880 KB
testcase_14 AC 188 ms
55,848 KB
testcase_15 AC 156 ms
55,868 KB
testcase_16 AC 155 ms
55,892 KB
testcase_17 AC 153 ms
55,712 KB
testcase_18 AC 191 ms
55,956 KB
testcase_19 AC 133 ms
55,368 KB
testcase_20 AC 188 ms
55,828 KB
testcase_21 AC 177 ms
55,788 KB
testcase_22 AC 127 ms
55,584 KB
testcase_23 AC 128 ms
55,216 KB
testcase_24 AC 128 ms
55,460 KB
testcase_25 AC 125 ms
55,660 KB
testcase_26 AC 185 ms
55,936 KB
testcase_27 AC 157 ms
55,760 KB
testcase_28 AC 192 ms
56,100 KB
testcase_29 AC 157 ms
55,788 KB
testcase_30 AC 139 ms
55,840 KB
testcase_31 AC 138 ms
55,728 KB
testcase_32 AC 153 ms
55,468 KB
testcase_33 AC 191 ms
56,016 KB
testcase_34 AC 188 ms
55,916 KB
testcase_35 AC 185 ms
55,788 KB
testcase_36 AC 144 ms
55,792 KB
testcase_37 AC 137 ms
55,688 KB
testcase_38 AC 155 ms
55,744 KB
testcase_39 AC 153 ms
56,000 KB
testcase_40 AC 193 ms
53,836 KB
testcase_41 AC 193 ms
56,152 KB
testcase_42 AC 155 ms
56,004 KB
testcase_43 AC 146 ms
55,236 KB
testcase_44 AC 186 ms
56,268 KB
testcase_45 AC 188 ms
55,492 KB
testcase_46 AC 132 ms
55,252 KB
testcase_47 AC 185 ms
56,068 KB
testcase_48 AC 145 ms
55,444 KB
testcase_49 AC 155 ms
55,820 KB
testcase_50 AC 130 ms
55,428 KB
testcase_51 AC 184 ms
55,836 KB
testcase_52 AC 186 ms
56,764 KB
testcase_53 AC 143 ms
55,420 KB
testcase_54 AC 187 ms
55,772 KB
testcase_55 AC 185 ms
55,956 KB
testcase_56 AC 189 ms
55,828 KB
testcase_57 AC 147 ms
55,580 KB
testcase_58 AC 185 ms
55,760 KB
testcase_59 AC 191 ms
55,960 KB
testcase_60 AC 135 ms
55,564 KB
testcase_61 AC 190 ms
56,008 KB
testcase_62 AC 153 ms
55,752 KB
testcase_63 AC 187 ms
55,976 KB
testcase_64 AC 195 ms
55,980 KB
testcase_65 AC 187 ms
55,808 KB
testcase_66 AC 132 ms
55,660 KB
testcase_67 AC 186 ms
56,004 KB
testcase_68 AC 188 ms
56,308 KB
testcase_69 AC 188 ms
55,900 KB
testcase_70 AC 157 ms
55,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no258;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] v = new int[n];
		for (int i = 0; i < n; i++) {
			v[i] = sc.nextInt();
		}
		int[][] dp = new int[n + 1][2];
		for (int i = 1; i <= n; i++) {
			dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1]);
			dp[i][1] = dp[i - 1][0] + v[i - 1];
		}
		System.out.println(Math.max(dp[n][0], dp[n][1]));
		ArrayList<Integer> sushi = new ArrayList<>();
		int now = dp[n][0] >= dp[n][1] ? 0 : 1;
		for(int i=n-1;i>=0;i--) {
			if (now == 0) {
				now = dp[i][0] >= dp[i][1] ? 0 : 1;
			}else{
				sushi.add(i+1);
				now = 0;
			}
		}
		Collections.reverse(sushi);
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<sushi.size();i++) {
			if (i > 0) {
				sb.append(' ');
			}
			sb.append(sushi.get(i));
		}
		System.out.println(sb);
	}

}
0