結果

問題 No.921 ずんだアロー
ユーザー NaoppyJNaoppyJ
提出日時 2019-11-08 22:44:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 543 ms / 2,000 ms
コード長 893 bytes
コンパイル時間 3,536 ms
コンパイル使用メモリ 78,368 KB
実行使用メモリ 60,928 KB
最終ジャッジ日時 2023-10-13 04:22:44
合計ジャッジ時間 13,691 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
55,900 KB
testcase_01 AC 127 ms
55,812 KB
testcase_02 AC 130 ms
54,028 KB
testcase_03 AC 127 ms
56,024 KB
testcase_04 AC 128 ms
55,772 KB
testcase_05 AC 126 ms
55,500 KB
testcase_06 AC 154 ms
55,900 KB
testcase_07 AC 144 ms
55,624 KB
testcase_08 AC 135 ms
55,864 KB
testcase_09 AC 137 ms
55,652 KB
testcase_10 AC 543 ms
60,420 KB
testcase_11 AC 514 ms
60,496 KB
testcase_12 AC 313 ms
60,188 KB
testcase_13 AC 483 ms
60,372 KB
testcase_14 AC 482 ms
60,472 KB
testcase_15 AC 428 ms
60,928 KB
testcase_16 AC 236 ms
59,632 KB
testcase_17 AC 490 ms
60,572 KB
testcase_18 AC 508 ms
60,568 KB
testcase_19 AC 514 ms
60,572 KB
testcase_20 AC 527 ms
60,116 KB
testcase_21 AC 525 ms
60,168 KB
testcase_22 AC 529 ms
60,228 KB
testcase_23 AC 522 ms
60,392 KB
testcase_24 AC 509 ms
60,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        }
        int prev = a[0];
        int ans = 0;
        boolean prevSkip = false;
        for (int num : a) {
            if(prev == num) {
                prevSkip = false;
                ans++;
                //System.out.print("o ");
            } else {
                if (prevSkip) {
                    prevSkip = false;
                    ans++;
                    //System.out.print("o ");
                } else {
                    prevSkip = true;
                    //System.out.print("x ");
                }
            }
            prev = num;
        }
        System.out.println(ans);
    }
}
0