結果

問題 No.871 かえるのうた
ユーザー ks2mks2m
提出日時 2019-08-30 21:49:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,156 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 2,884 ms
コンパイル使用メモリ 77,992 KB
実行使用メモリ 143,860 KB
最終ジャッジ日時 2024-05-07 16:22:25
合計ジャッジ時間 11,741 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
49,912 KB
testcase_01 AC 51 ms
50,236 KB
testcase_02 AC 48 ms
50,224 KB
testcase_03 AC 49 ms
50,260 KB
testcase_04 AC 48 ms
50,092 KB
testcase_05 AC 49 ms
49,948 KB
testcase_06 AC 49 ms
50,212 KB
testcase_07 AC 50 ms
50,280 KB
testcase_08 AC 72 ms
51,568 KB
testcase_09 AC 88 ms
51,808 KB
testcase_10 AC 56 ms
50,484 KB
testcase_11 AC 73 ms
51,104 KB
testcase_12 AC 148 ms
57,264 KB
testcase_13 AC 98 ms
52,128 KB
testcase_14 AC 347 ms
71,136 KB
testcase_15 AC 325 ms
70,204 KB
testcase_16 AC 1,156 ms
143,860 KB
testcase_17 AC 312 ms
68,816 KB
testcase_18 AC 161 ms
55,196 KB
testcase_19 AC 344 ms
69,864 KB
testcase_20 AC 164 ms
57,812 KB
testcase_21 AC 246 ms
60,572 KB
testcase_22 AC 49 ms
50,336 KB
testcase_23 AC 49 ms
50,032 KB
testcase_24 AC 56 ms
50,344 KB
testcase_25 AC 89 ms
51,656 KB
testcase_26 AC 129 ms
54,744 KB
testcase_27 AC 123 ms
53,992 KB
testcase_28 AC 50 ms
50,036 KB
testcase_29 AC 220 ms
62,488 KB
testcase_30 AC 342 ms
64,176 KB
testcase_31 AC 89 ms
51,688 KB
testcase_32 AC 281 ms
63,672 KB
testcase_33 AC 285 ms
64,756 KB
testcase_34 AC 182 ms
55,180 KB
testcase_35 AC 264 ms
62,940 KB
testcase_36 AC 274 ms
65,200 KB
testcase_37 AC 263 ms
60,840 KB
testcase_38 AC 373 ms
65,936 KB
testcase_39 AC 343 ms
65,416 KB
testcase_40 AC 209 ms
63,256 KB
testcase_41 AC 49 ms
50,228 KB
testcase_42 AC 200 ms
63,116 KB
testcase_43 AC 47 ms
50,096 KB
testcase_44 AC 51 ms
50,100 KB
testcase_45 AC 75 ms
51,396 KB
testcase_46 AC 49 ms
50,212 KB
testcase_47 AC 49 ms
50,284 KB
testcase_48 AC 51 ms
50,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]) - 1;
		sa = br.readLine().split(" ");
		long[] x = new long[n];
		for (int i = 0; i < n; i++) {
			x[i] = Long.parseLong(sa[i]);
		}
		sa = br.readLine().split(" ");
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sa[i]);
		}
		br.close();

		Queue<Integer> que = new ArrayDeque<>();
		que.add(k);
		boolean[] flg = new boolean[n];
		flg[k] = true;
		long min = x[k];
		long max = x[k];
		while (!que.isEmpty()) {
			int cur = que.poll();
			long l = x[cur] - a[cur];
			if (l < min) {
				min = l;
				for (int i = cur - 1; i >= 0 && l <= x[i]; i--) {
					flg[i] = true;
					que.add(i);
				}
			}
			long r = x[cur] + a[cur];
			if (max < r) {
				max = r;
				for (int i = cur + 1; i < n && x[i] <= r; i++) {
					flg[i] = true;
					que.add(i);
				}
			}
		}

		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (flg[i]) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}
0