結果

問題 No.871 かえるのうた
ユーザー yakamotoyakamoto
提出日時 2019-08-31 00:38:30
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,003 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 16,708 ms
コンパイル使用メモリ 432,804 KB
実行使用メモリ 74,264 KB
最終ジャッジ日時 2023-08-20 09:27:18
合計ジャッジ時間 47,594 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 341 ms
53,036 KB
testcase_01 AC 321 ms
53,220 KB
testcase_02 AC 318 ms
52,868 KB
testcase_03 AC 322 ms
53,368 KB
testcase_04 AC 321 ms
53,260 KB
testcase_05 AC 329 ms
53,260 KB
testcase_06 AC 312 ms
52,868 KB
testcase_07 AC 318 ms
53,140 KB
testcase_08 AC 404 ms
53,512 KB
testcase_09 AC 433 ms
55,968 KB
testcase_10 AC 347 ms
53,356 KB
testcase_11 AC 366 ms
53,676 KB
testcase_12 AC 567 ms
59,344 KB
testcase_13 AC 454 ms
55,848 KB
testcase_14 AC 910 ms
71,464 KB
testcase_15 AC 870 ms
70,020 KB
testcase_16 AC 1,003 ms
73,288 KB
testcase_17 AC 866 ms
73,956 KB
testcase_18 AC 555 ms
57,984 KB
testcase_19 AC 923 ms
69,528 KB
testcase_20 AC 538 ms
61,020 KB
testcase_21 AC 761 ms
60,036 KB
testcase_22 AC 336 ms
53,012 KB
testcase_23 AC 319 ms
53,124 KB
testcase_24 AC 320 ms
53,016 KB
testcase_25 AC 414 ms
53,444 KB
testcase_26 AC 511 ms
56,508 KB
testcase_27 AC 543 ms
58,548 KB
testcase_28 AC 321 ms
53,028 KB
testcase_29 AC 740 ms
63,708 KB
testcase_30 AC 858 ms
72,440 KB
testcase_31 AC 407 ms
53,480 KB
testcase_32 AC 831 ms
62,060 KB
testcase_33 AC 814 ms
74,264 KB
testcase_34 AC 603 ms
59,652 KB
testcase_35 AC 734 ms
62,304 KB
testcase_36 AC 751 ms
66,236 KB
testcase_37 AC 795 ms
62,104 KB
testcase_38 AC 996 ms
73,336 KB
testcase_39 AC 941 ms
74,216 KB
testcase_40 AC 776 ms
64,688 KB
testcase_41 AC 308 ms
53,208 KB
testcase_42 AC 789 ms
63,880 KB
testcase_43 AC 305 ms
53,120 KB
testcase_44 AC 314 ms
53,036 KB
testcase_45 AC 386 ms
53,464 KB
testcase_46 AC 313 ms
53,092 KB
testcase_47 AC 303 ms
53,060 KB
testcase_48 AC 303 ms
53,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import kotlin.math.max
import kotlin.math.min

// なんか本番でエラーでる
private val isDebug = runCatching {
  System.getenv("MY_DEBUG") != null
}.fold({it}, {false})

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }.toIntArray()
private fun readLongs() = readStrings().map { it.toLong() }.toLongArray()
private fun debug(msg: () -> String) {
  if (isDebug) System.err.println(msg())
}
private fun debug(a: LongArray) {
  if (isDebug) debug{a.joinToString(" ")}
}

val MOD = 1000000007

data class Entry(val i: Int, val x: Long)

fun main() {
  var (N, K) = readInts()
  K--
  val X = readLongs()
  val A = readLongs()
  val set = java.util.TreeSet<Entry>(Comparator<Entry> { o1, o2 ->
    o1.x.compareTo(o2.x)
  })
  for (i in 0 until N) {
    set.add(Entry(i, X[i]))
  }

  var ans = 0
  var l = X[K]
  var r = X[K]
  while(true) {
    val e1 = set.higher(Entry(-1, l - 1))
    val e2 = set.lower(Entry(-1, r + 1))
    debug{"l:$l r:$r"}
    if (e1 != null && e2 != null && e1.x <= e2.x) {
      set.remove(e1)
      l = min(l, e1.x - A[e1.i])
      r = max(r, e1.x + A[e1.i])
      ans++
    } else {
      break
    }
  }

  println(ans)
}
0