結果
問題 | No.871 かえるのうた |
ユーザー | tenten |
提出日時 | 2021-03-16 10:41:50 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 437 ms / 2,000 ms |
コード長 | 1,597 bytes |
コンパイル時間 | 2,395 ms |
コンパイル使用メモリ | 74,312 KB |
実行使用メモリ | 76,244 KB |
最終ジャッジ日時 | 2023-08-20 09:39:24 |
合計ジャッジ時間 | 12,422 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
49,476 KB |
testcase_01 | AC | 45 ms
49,172 KB |
testcase_02 | AC | 45 ms
49,480 KB |
testcase_03 | AC | 47 ms
49,544 KB |
testcase_04 | AC | 47 ms
49,192 KB |
testcase_05 | AC | 46 ms
49,356 KB |
testcase_06 | AC | 46 ms
49,736 KB |
testcase_07 | AC | 47 ms
49,548 KB |
testcase_08 | AC | 83 ms
51,932 KB |
testcase_09 | AC | 86 ms
51,736 KB |
testcase_10 | AC | 56 ms
50,368 KB |
testcase_11 | AC | 64 ms
51,012 KB |
testcase_12 | AC | 138 ms
56,968 KB |
testcase_13 | AC | 95 ms
51,996 KB |
testcase_14 | AC | 386 ms
73,236 KB |
testcase_15 | AC | 369 ms
76,244 KB |
testcase_16 | AC | 437 ms
76,028 KB |
testcase_17 | AC | 351 ms
72,340 KB |
testcase_18 | AC | 138 ms
55,532 KB |
testcase_19 | AC | 417 ms
76,008 KB |
testcase_20 | AC | 122 ms
52,672 KB |
testcase_21 | AC | 249 ms
63,036 KB |
testcase_22 | AC | 47 ms
49,416 KB |
testcase_23 | AC | 47 ms
49,392 KB |
testcase_24 | AC | 45 ms
49,588 KB |
testcase_25 | AC | 70 ms
51,876 KB |
testcase_26 | AC | 107 ms
54,536 KB |
testcase_27 | AC | 119 ms
54,852 KB |
testcase_28 | AC | 46 ms
49,472 KB |
testcase_29 | AC | 235 ms
62,900 KB |
testcase_30 | AC | 332 ms
67,268 KB |
testcase_31 | AC | 86 ms
52,212 KB |
testcase_32 | AC | 268 ms
67,540 KB |
testcase_33 | AC | 340 ms
73,188 KB |
testcase_34 | AC | 175 ms
55,616 KB |
testcase_35 | AC | 253 ms
65,972 KB |
testcase_36 | AC | 316 ms
68,264 KB |
testcase_37 | AC | 249 ms
60,984 KB |
testcase_38 | AC | 347 ms
70,184 KB |
testcase_39 | AC | 363 ms
68,016 KB |
testcase_40 | AC | 229 ms
62,020 KB |
testcase_41 | AC | 45 ms
49,400 KB |
testcase_42 | AC | 225 ms
62,688 KB |
testcase_43 | AC | 46 ms
49,396 KB |
testcase_44 | AC | 50 ms
49,552 KB |
testcase_45 | AC | 66 ms
51,420 KB |
testcase_46 | AC | 45 ms
49,400 KB |
testcase_47 | AC | 44 ms
47,148 KB |
testcase_48 | AC | 46 ms
49,328 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int n = Integer.parseInt(first[0]); int k = Integer.parseInt(first[1]) - 1; String[] second = br.readLine().split(" ", n); String[] third = br.readLine().split(" ", n); Frog[] frogs = new Frog[n]; for (int i = 0; i < n; i++) { frogs[i] = new Frog(Long.parseLong(second[i]), Long.parseLong(third[i])); } int left = k; int right = k; long min = frogs[k].position - frogs[k].strength; long max = frogs[k].position + frogs[k].strength; boolean flag = true; while (flag) { flag = false; while (left > 0 && frogs[left - 1].position >= min) { min = Math.min(min, frogs[left - 1].position - frogs[left - 1].strength); max = Math.max(max, frogs[left - 1].position + frogs[left - 1].strength); left--; flag = true; } while (right < n - 1 && frogs[right + 1].position <= max) { min = Math.min(min, frogs[right + 1].position - frogs[right + 1].strength); max = Math.max(max, frogs[right + 1].position + frogs[right + 1].strength); right++; flag = true; } } System.out.println(right - left + 1); } static class Frog { long position; long strength; public Frog(long position, long strength) { this.position = position; this.strength = strength; } } }