結果

問題 No.921 ずんだアロー
ユーザー NaoppyJNaoppyJ
提出日時 2019-11-08 22:05:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,149 bytes
コンパイル時間 2,024 ms
コンパイル使用メモリ 74,732 KB
実行使用メモリ 64,368 KB
最終ジャッジ日時 2023-10-13 03:52:41
合計ジャッジ時間 11,873 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,608 KB
testcase_01 AC 120 ms
56,196 KB
testcase_02 AC 121 ms
55,776 KB
testcase_03 AC 123 ms
56,128 KB
testcase_04 AC 122 ms
56,116 KB
testcase_05 AC 121 ms
56,488 KB
testcase_06 AC 159 ms
55,700 KB
testcase_07 AC 137 ms
55,728 KB
testcase_08 AC 127 ms
56,144 KB
testcase_09 AC 132 ms
55,548 KB
testcase_10 AC 539 ms
62,628 KB
testcase_11 AC 521 ms
60,280 KB
testcase_12 AC 335 ms
60,124 KB
testcase_13 AC 492 ms
60,376 KB
testcase_14 AC 496 ms
64,368 KB
testcase_15 AC 408 ms
45,960 KB
testcase_16 AC 227 ms
43,744 KB
testcase_17 AC 478 ms
46,764 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 524 ms
48,984 KB
testcase_24 AC 495 ms
46,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        ArrayList<Integer> list = new ArrayList<>();
        int prev = a[0];
        int count = 0;
        for (int i : a) {
            if (i == prev) {
                count++;
            } else {
                list.add(count);
                count = 1;
                prev = i;
            }
        }
        list.add(count);

//        for (int i = 0; i < list.size(); i++) {
//            System.out.print(list.get(i)+" ");
//        }
//        System.out.println();

        long[][] dp = new long[list.size() + 10][2];
        dp[0][0] = 0;
        dp[0][1] = 0;

        for (int i = 1; i <= list.size(); i++) {
            dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1]);
            dp[i][1] = dp[i - 1][0] + list.get(i - 1);
        }

        System.out.println(Math.max(dp[list.size()][0], dp[list.size()][1]));
    }
}
0