結果

問題 No.921 ずんだアロー
ユーザー NaoppyJNaoppyJ
提出日時 2019-11-08 21:52:03
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,232 bytes
コンパイル時間 2,703 ms
コンパイル使用メモリ 77,408 KB
実行使用メモリ 62,384 KB
最終ジャッジ日時 2023-10-13 03:47:33
合計ジャッジ時間 12,087 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,892 KB
testcase_01 AC 127 ms
55,892 KB
testcase_02 AC 127 ms
55,536 KB
testcase_03 AC 126 ms
55,844 KB
testcase_04 AC 125 ms
56,200 KB
testcase_05 AC 125 ms
56,120 KB
testcase_06 AC 157 ms
55,536 KB
testcase_07 AC 144 ms
55,452 KB
testcase_08 AC 135 ms
55,740 KB
testcase_09 AC 139 ms
55,724 KB
testcase_10 AC 517 ms
60,556 KB
testcase_11 AC 536 ms
60,420 KB
testcase_12 AC 333 ms
60,152 KB
testcase_13 AC 495 ms
60,944 KB
testcase_14 AC 495 ms
59,996 KB
testcase_15 AC 421 ms
60,280 KB
testcase_16 AC 233 ms
59,060 KB
testcase_17 AC 505 ms
60,636 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 531 ms
60,480 KB
testcase_24 AC 519 ms
60,316 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);
        list.add(0);
        list.add(0);
        list.add(0);

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

        int ans = 0;

        for (int i = 0; i < list.size() - 3; i++) {
            if (list.get(i) - list.get(i + 1) >= list.get(i + 1) - list.get(i) - list.get(i + 2)) {
                ans += list.get(i);
                i++;
            } else {
                ans += list.get(i + 1);
                i+=2;
            }
        }

        System.out.println(ans);
    }
}
0