結果

問題 No.258 回転寿司(2)
ユーザー ぴろずぴろず
提出日時 2015-07-31 22:53:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 967 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 78,660 KB
実行使用メモリ 42,652 KB
最終ジャッジ日時 2024-04-24 11:03:57
合計ジャッジ時間 15,524 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
42,516 KB
testcase_01 AC 165 ms
42,400 KB
testcase_02 AC 173 ms
42,220 KB
testcase_03 AC 127 ms
40,620 KB
testcase_04 AC 177 ms
41,848 KB
testcase_05 AC 153 ms
41,764 KB
testcase_06 AC 160 ms
42,596 KB
testcase_07 AC 130 ms
41,560 KB
testcase_08 AC 153 ms
41,760 KB
testcase_09 AC 138 ms
41,388 KB
testcase_10 AC 120 ms
41,012 KB
testcase_11 AC 133 ms
41,708 KB
testcase_12 AC 159 ms
41,856 KB
testcase_13 AC 132 ms
41,452 KB
testcase_14 AC 167 ms
42,088 KB
testcase_15 AC 133 ms
41,032 KB
testcase_16 AC 142 ms
41,556 KB
testcase_17 AC 148 ms
41,404 KB
testcase_18 AC 181 ms
42,128 KB
testcase_19 AC 117 ms
41,020 KB
testcase_20 AC 162 ms
41,876 KB
testcase_21 AC 162 ms
42,412 KB
testcase_22 AC 115 ms
41,260 KB
testcase_23 AC 114 ms
41,136 KB
testcase_24 AC 103 ms
40,192 KB
testcase_25 AC 105 ms
40,168 KB
testcase_26 AC 172 ms
42,232 KB
testcase_27 AC 142 ms
41,448 KB
testcase_28 AC 166 ms
42,652 KB
testcase_29 AC 140 ms
41,376 KB
testcase_30 AC 133 ms
41,664 KB
testcase_31 AC 137 ms
41,464 KB
testcase_32 AC 157 ms
41,576 KB
testcase_33 AC 169 ms
42,188 KB
testcase_34 AC 155 ms
41,888 KB
testcase_35 AC 145 ms
41,772 KB
testcase_36 AC 127 ms
41,460 KB
testcase_37 AC 121 ms
41,132 KB
testcase_38 AC 149 ms
41,676 KB
testcase_39 AC 144 ms
41,784 KB
testcase_40 AC 172 ms
41,848 KB
testcase_41 AC 159 ms
42,320 KB
testcase_42 AC 134 ms
41,300 KB
testcase_43 AC 123 ms
41,248 KB
testcase_44 AC 160 ms
42,468 KB
testcase_45 AC 160 ms
42,140 KB
testcase_46 AC 117 ms
41,380 KB
testcase_47 AC 157 ms
42,252 KB
testcase_48 AC 124 ms
41,192 KB
testcase_49 AC 136 ms
41,448 KB
testcase_50 AC 110 ms
40,044 KB
testcase_51 AC 165 ms
42,136 KB
testcase_52 AC 169 ms
41,760 KB
testcase_53 AC 156 ms
41,492 KB
testcase_54 AC 151 ms
42,024 KB
testcase_55 AC 167 ms
42,464 KB
testcase_56 AC 161 ms
42,436 KB
testcase_57 AC 127 ms
41,240 KB
testcase_58 AC 155 ms
42,108 KB
testcase_59 AC 171 ms
42,008 KB
testcase_60 AC 135 ms
41,760 KB
testcase_61 AC 160 ms
42,016 KB
testcase_62 AC 153 ms
41,524 KB
testcase_63 AC 161 ms
42,260 KB
testcase_64 AC 173 ms
42,424 KB
testcase_65 AC 157 ms
42,068 KB
testcase_66 AC 111 ms
41,228 KB
testcase_67 AC 161 ms
42,504 KB
testcase_68 AC 164 ms
42,368 KB
testcase_69 AC 162 ms
41,956 KB
testcase_70 AC 143 ms
41,544 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