結果

問題 No.871 かえるのうた
ユーザー ks2mks2m
提出日時 2019-08-30 21:49:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,172 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 3,179 ms
コンパイル使用メモリ 74,832 KB
実行使用メモリ 143,840 KB
最終ジャッジ日時 2023-08-20 09:18:11
合計ジャッジ時間 13,743 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,320 KB
testcase_01 AC 43 ms
49,424 KB
testcase_02 AC 43 ms
49,228 KB
testcase_03 AC 46 ms
49,420 KB
testcase_04 AC 47 ms
49,468 KB
testcase_05 AC 47 ms
49,304 KB
testcase_06 AC 47 ms
49,272 KB
testcase_07 AC 50 ms
49,264 KB
testcase_08 AC 81 ms
51,988 KB
testcase_09 AC 87 ms
52,280 KB
testcase_10 AC 56 ms
50,828 KB
testcase_11 AC 59 ms
50,592 KB
testcase_12 AC 153 ms
54,216 KB
testcase_13 AC 93 ms
52,604 KB
testcase_14 AC 349 ms
71,044 KB
testcase_15 AC 352 ms
71,000 KB
testcase_16 AC 1,172 ms
143,840 KB
testcase_17 AC 338 ms
65,604 KB
testcase_18 AC 164 ms
55,980 KB
testcase_19 AC 373 ms
70,908 KB
testcase_20 AC 163 ms
58,128 KB
testcase_21 AC 259 ms
61,724 KB
testcase_22 AC 46 ms
49,452 KB
testcase_23 AC 47 ms
49,240 KB
testcase_24 AC 44 ms
49,680 KB
testcase_25 AC 86 ms
52,448 KB
testcase_26 AC 123 ms
54,892 KB
testcase_27 AC 109 ms
55,124 KB
testcase_28 AC 44 ms
49,432 KB
testcase_29 AC 236 ms
63,156 KB
testcase_30 AC 343 ms
66,136 KB
testcase_31 AC 77 ms
52,340 KB
testcase_32 AC 303 ms
65,056 KB
testcase_33 AC 306 ms
65,088 KB
testcase_34 AC 164 ms
55,380 KB
testcase_35 AC 284 ms
62,712 KB
testcase_36 AC 307 ms
65,976 KB
testcase_37 AC 303 ms
61,464 KB
testcase_38 AC 437 ms
65,876 KB
testcase_39 AC 356 ms
66,028 KB
testcase_40 AC 220 ms
60,348 KB
testcase_41 AC 43 ms
49,348 KB
testcase_42 AC 228 ms
60,584 KB
testcase_43 AC 43 ms
49,308 KB
testcase_44 AC 48 ms
49,372 KB
testcase_45 AC 60 ms
50,532 KB
testcase_46 AC 44 ms
49,320 KB
testcase_47 AC 43 ms
49,712 KB
testcase_48 AC 43 ms
49,628 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