結果

問題 No.45 回転寿司
ユーザー kuramubonnkuramubonn
提出日時 2023-02-02 23:48:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 200 ms / 5,000 ms
コード長 813 bytes
コンパイル時間 6,408 ms
コンパイル使用メモリ 73,816 KB
実行使用メモリ 57,356 KB
最終ジャッジ日時 2023-09-15 04:31:43
合計ジャッジ時間 12,101 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 180 ms
55,772 KB
testcase_01 AC 194 ms
56,316 KB
testcase_02 AC 194 ms
57,084 KB
testcase_03 AC 198 ms
56,524 KB
testcase_04 AC 185 ms
56,180 KB
testcase_05 AC 133 ms
55,784 KB
testcase_06 AC 187 ms
56,352 KB
testcase_07 AC 198 ms
56,328 KB
testcase_08 AC 145 ms
55,948 KB
testcase_09 AC 197 ms
56,940 KB
testcase_10 AC 165 ms
55,968 KB
testcase_11 AC 141 ms
55,764 KB
testcase_12 AC 197 ms
56,956 KB
testcase_13 AC 129 ms
55,536 KB
testcase_14 AC 129 ms
56,160 KB
testcase_15 AC 155 ms
56,048 KB
testcase_16 AC 152 ms
56,456 KB
testcase_17 AC 179 ms
56,344 KB
testcase_18 AC 152 ms
55,604 KB
testcase_19 AC 192 ms
56,332 KB
testcase_20 AC 130 ms
55,920 KB
testcase_21 AC 129 ms
55,824 KB
testcase_22 AC 122 ms
55,684 KB
testcase_23 AC 122 ms
55,744 KB
testcase_24 AC 122 ms
55,788 KB
testcase_25 AC 122 ms
55,716 KB
testcase_26 AC 151 ms
56,336 KB
testcase_27 AC 190 ms
57,356 KB
testcase_28 AC 185 ms
56,640 KB
testcase_29 AC 187 ms
56,440 KB
testcase_30 AC 193 ms
56,440 KB
testcase_31 AC 123 ms
56,044 KB
testcase_32 AC 122 ms
56,032 KB
testcase_33 AC 200 ms
56,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] data = new int [sc.nextInt()];
		int[] vect = new int [data.length];
		
		for(int i = 0 ; i < data.length ; i++)data[i] = sc.nextInt();
		if(data.length == 1) {
			System.out.println(data[0]);
			return;
		}
		if(data.length == 2) {
			if(data[0] < data[1])System.out.println(data[1]);
			else System.out.println(data[0]);
			return;
		}
		vect[0] = data[0];
		vect[1] = data[1];
		for(int i = 2 ; i < data.length ; i++) {
			int max = 0;
			for(int j = 0 ; j < i - 1 ; j++) {
				if(data[i] + vect[j] > max)max = data[i] + vect[j];
			}
			vect[i] = max;
		}
		int max = 0;
		for(int i = 0 ; i < vect.length ; i++) 
			if(max < vect[i])max = vect[i];
		System.out.println(max);
	}
}
0