結果

問題 No.921 ずんだアロー
ユーザー tentententen
提出日時 2020-08-27 01:49:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 552 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 78,072 KB
実行使用メモリ 49,352 KB
最終ジャッジ日時 2024-04-25 04:26:46
合計ジャッジ時間 10,603 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
41,116 KB
testcase_01 AC 110 ms
41,136 KB
testcase_02 AC 108 ms
40,792 KB
testcase_03 AC 103 ms
40,348 KB
testcase_04 AC 115 ms
41,468 KB
testcase_05 AC 130 ms
41,112 KB
testcase_06 AC 141 ms
41,668 KB
testcase_07 AC 122 ms
41,192 KB
testcase_08 AC 114 ms
41,336 KB
testcase_09 AC 125 ms
41,664 KB
testcase_10 AC 548 ms
49,352 KB
testcase_11 AC 552 ms
49,284 KB
testcase_12 AC 345 ms
48,104 KB
testcase_13 AC 510 ms
48,640 KB
testcase_14 AC 505 ms
49,268 KB
testcase_15 AC 406 ms
48,052 KB
testcase_16 AC 221 ms
45,904 KB
testcase_17 AC 504 ms
49,216 KB
testcase_18 AC 439 ms
47,572 KB
testcase_19 AC 433 ms
46,580 KB
testcase_20 AC 439 ms
47,876 KB
testcase_21 AC 446 ms
47,648 KB
testcase_22 AC 433 ms
47,460 KB
testcase_23 AC 451 ms
47,424 KB
testcase_24 AC 448 ms
47,696 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