結果

問題 No.921 ずんだアロー
ユーザー tentententen
提出日時 2020-08-27 01:26:38
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 835 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 78,276 KB
実行使用メモリ 49,024 KB
最終ジャッジ日時 2024-04-25 04:26:27
合計ジャッジ時間 11,265 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
41,076 KB
testcase_01 AC 114 ms
41,204 KB
testcase_02 AC 114 ms
41,228 KB
testcase_03 AC 116 ms
41,032 KB
testcase_04 AC 114 ms
41,424 KB
testcase_05 AC 108 ms
39,860 KB
testcase_06 AC 141 ms
41,524 KB
testcase_07 AC 128 ms
41,292 KB
testcase_08 AC 116 ms
41,392 KB
testcase_09 AC 121 ms
41,112 KB
testcase_10 AC 537 ms
49,012 KB
testcase_11 AC 535 ms
48,996 KB
testcase_12 AC 280 ms
46,740 KB
testcase_13 AC 505 ms
48,544 KB
testcase_14 AC 416 ms
47,716 KB
testcase_15 AC 438 ms
48,052 KB
testcase_16 AC 203 ms
45,624 KB
testcase_17 AC 511 ms
49,024 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 494 ms
48,948 KB
testcase_24 AC 443 ms
47,400 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] = dp[0][i - 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