結果

問題 No.921 ずんだアロー
ユーザー tentententen
提出日時 2020-08-27 01:49:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 503 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 1,958 ms
コンパイル使用メモリ 74,324 KB
実行使用メモリ 62,512 KB
最終ジャッジ日時 2023-08-07 10:32:37
合計ジャッジ時間 11,112 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,660 KB
testcase_01 AC 119 ms
55,900 KB
testcase_02 AC 119 ms
56,164 KB
testcase_03 AC 120 ms
56,160 KB
testcase_04 AC 119 ms
56,160 KB
testcase_05 AC 118 ms
55,664 KB
testcase_06 AC 144 ms
55,820 KB
testcase_07 AC 130 ms
56,032 KB
testcase_08 AC 122 ms
56,160 KB
testcase_09 AC 126 ms
56,228 KB
testcase_10 AC 503 ms
60,728 KB
testcase_11 AC 486 ms
62,512 KB
testcase_12 AC 313 ms
59,728 KB
testcase_13 AC 471 ms
60,220 KB
testcase_14 AC 459 ms
60,404 KB
testcase_15 AC 415 ms
60,544 KB
testcase_16 AC 222 ms
58,916 KB
testcase_17 AC 459 ms
60,452 KB
testcase_18 AC 482 ms
60,236 KB
testcase_19 AC 492 ms
60,420 KB
testcase_20 AC 483 ms
60,164 KB
testcase_21 AC 491 ms
60,348 KB
testcase_22 AC 499 ms
60,336 KB
testcase_23 AC 497 ms
60,484 KB
testcase_24 AC 487 ms
60,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int prev = sc.nextInt();
    	int count = 1;
    	ArrayList<Integer> list = new ArrayList<>();
    	for (int i = 1; i < n; i++) {
    	    int x = sc.nextInt();
    	    if (x == prev) {
    	        count++;
    	    } else {
    	        list.add(count);
    	        count = 1;
    	        prev = x;
    	    }
    	}
    	list.add(count);
    	int length = list.size();
    	int[][] dp = new int[2][length];
    	dp[1][0] = list.get(0);
    	for (int i = 1; i < length; i++) {
    	    dp[1][i] = Math.max(dp[0][i - 1], dp[1][i - 1] - 1) + list.get(i);
    	    dp[0][i] = Math.max(dp[0][i - 1], dp[1][i - 1]);
    	}
    	System.out.println(Math.max(dp[0][length - 1], dp[1][length - 1]));
    }
}
0