結果

問題 No.1007 コイン集め
ユーザー htensaihtensai
提出日時 2020-03-24 14:47:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 631 ms / 1,500 ms
コード長 972 bytes
コンパイル時間 2,219 ms
コンパイル使用メモリ 73,844 KB
実行使用メモリ 60,880 KB
最終ジャッジ日時 2023-08-30 05:29:08
合計ジャッジ時間 11,632 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
56,064 KB
testcase_01 AC 124 ms
55,956 KB
testcase_02 AC 132 ms
55,868 KB
testcase_03 AC 121 ms
55,784 KB
testcase_04 AC 134 ms
55,492 KB
testcase_05 AC 128 ms
55,440 KB
testcase_06 AC 129 ms
55,960 KB
testcase_07 AC 135 ms
55,704 KB
testcase_08 AC 134 ms
56,044 KB
testcase_09 AC 134 ms
55,804 KB
testcase_10 AC 135 ms
55,752 KB
testcase_11 AC 131 ms
55,888 KB
testcase_12 AC 631 ms
60,880 KB
testcase_13 AC 609 ms
60,576 KB
testcase_14 AC 589 ms
60,736 KB
testcase_15 AC 527 ms
60,596 KB
testcase_16 AC 480 ms
60,664 KB
testcase_17 AC 490 ms
60,392 KB
testcase_18 AC 594 ms
60,844 KB
testcase_19 AC 598 ms
60,708 KB
testcase_20 AC 606 ms
60,660 KB
testcase_21 AC 596 ms
60,512 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 k = sc.nextInt();
        int[] arr = new int[n + 2];
        for (int i = 1; i <= n; i++) {
            arr[i] = sc.nextInt();
        }
        if (arr[k] == 0) {
            System.out.println(0);
            return;
        }
        long left = 0;
        int idx = k - 1;
        while (arr[idx] > 1) {
            left += arr[idx];
            idx--;
        }
        if (arr[idx] == 1) {
            left++;
        }
        long right = 0;
        idx = k + 1;
        while (arr[idx] > 1) {
            right += arr[idx];
            idx++;
        }
        if (arr[idx] == 1) {
            right++;
        }
        if (arr[k] == 1) {
            System.out.println(Math.max(left, right) + 1);
        } else {
            System.out.println(left + right + arr[k]);
        }
    }
}
0