結果

問題 No.854 公平なりんご分配
ユーザー pekempeypekempey
提出日時 2019-07-27 03:12:00
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,233 ms / 3,153 ms
コード長 1,853 bytes
コンパイル時間 15,700 ms
コンパイル使用メモリ 443,312 KB
実行使用メモリ 75,976 KB
最終ジャッジ日時 2024-11-20 19:11:59
合計ジャッジ時間 72,431 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 303 ms
64,012 KB
testcase_01 AC 302 ms
63,884 KB
testcase_02 AC 308 ms
63,952 KB
testcase_03 AC 306 ms
63,968 KB
testcase_04 AC 305 ms
63,896 KB
testcase_05 AC 304 ms
63,964 KB
testcase_06 AC 308 ms
63,920 KB
testcase_07 AC 315 ms
63,980 KB
testcase_08 AC 307 ms
63,860 KB
testcase_09 AC 307 ms
64,000 KB
testcase_10 AC 303 ms
63,964 KB
testcase_11 AC 302 ms
63,960 KB
testcase_12 AC 311 ms
63,976 KB
testcase_13 AC 309 ms
63,988 KB
testcase_14 AC 311 ms
63,972 KB
testcase_15 AC 308 ms
63,780 KB
testcase_16 AC 305 ms
63,984 KB
testcase_17 AC 306 ms
63,892 KB
testcase_18 AC 306 ms
63,780 KB
testcase_19 AC 305 ms
63,972 KB
testcase_20 AC 307 ms
63,888 KB
testcase_21 AC 306 ms
63,780 KB
testcase_22 AC 368 ms
64,396 KB
testcase_23 AC 361 ms
64,436 KB
testcase_24 AC 390 ms
64,440 KB
testcase_25 AC 365 ms
64,500 KB
testcase_26 AC 378 ms
64,420 KB
testcase_27 AC 361 ms
64,548 KB
testcase_28 AC 381 ms
64,548 KB
testcase_29 AC 343 ms
64,272 KB
testcase_30 AC 358 ms
64,340 KB
testcase_31 AC 394 ms
64,640 KB
testcase_32 AC 450 ms
64,604 KB
testcase_33 AC 617 ms
69,328 KB
testcase_34 AC 637 ms
69,452 KB
testcase_35 AC 608 ms
69,740 KB
testcase_36 AC 581 ms
69,544 KB
testcase_37 AC 482 ms
64,628 KB
testcase_38 AC 435 ms
64,556 KB
testcase_39 AC 715 ms
71,788 KB
testcase_40 AC 595 ms
69,588 KB
testcase_41 AC 624 ms
69,648 KB
testcase_42 AC 645 ms
69,528 KB
testcase_43 AC 669 ms
69,544 KB
testcase_44 AC 688 ms
69,604 KB
testcase_45 AC 670 ms
71,528 KB
testcase_46 AC 728 ms
71,736 KB
testcase_47 AC 576 ms
69,356 KB
testcase_48 AC 629 ms
69,488 KB
testcase_49 AC 607 ms
69,516 KB
testcase_50 AC 442 ms
64,552 KB
testcase_51 AC 737 ms
71,980 KB
testcase_52 AC 761 ms
71,636 KB
testcase_53 AC 602 ms
69,328 KB
testcase_54 AC 733 ms
71,500 KB
testcase_55 AC 553 ms
69,544 KB
testcase_56 AC 455 ms
64,668 KB
testcase_57 AC 606 ms
69,460 KB
testcase_58 AC 713 ms
71,812 KB
testcase_59 AC 443 ms
64,668 KB
testcase_60 AC 652 ms
69,468 KB
testcase_61 AC 593 ms
69,428 KB
testcase_62 AC 682 ms
71,668 KB
testcase_63 AC 655 ms
69,576 KB
testcase_64 AC 535 ms
69,344 KB
testcase_65 AC 639 ms
69,504 KB
testcase_66 AC 606 ms
69,328 KB
testcase_67 AC 699 ms
69,504 KB
testcase_68 AC 712 ms
71,560 KB
testcase_69 AC 500 ms
64,716 KB
testcase_70 AC 539 ms
69,520 KB
testcase_71 AC 563 ms
69,424 KB
testcase_72 AC 615 ms
69,604 KB
testcase_73 AC 579 ms
69,400 KB
testcase_74 AC 711 ms
69,516 KB
testcase_75 AC 602 ms
69,704 KB
testcase_76 AC 649 ms
69,284 KB
testcase_77 AC 665 ms
69,344 KB
testcase_78 AC 730 ms
71,724 KB
testcase_79 AC 710 ms
71,540 KB
testcase_80 AC 692 ms
69,300 KB
testcase_81 AC 626 ms
69,440 KB
testcase_82 AC 1,009 ms
75,976 KB
testcase_83 AC 1,117 ms
75,788 KB
testcase_84 AC 1,233 ms
75,940 KB
testcase_85 AC 1,153 ms
75,972 KB
testcase_86 AC 907 ms
75,640 KB
testcase_87 AC 1,020 ms
75,728 KB
testcase_88 AC 1,032 ms
75,904 KB
testcase_89 AC 1,034 ms
75,924 KB
testcase_90 AC 1,020 ms
75,796 KB
testcase_91 AC 1,020 ms
75,860 KB
testcase_92 AC 1,171 ms
75,876 KB
testcase_93 AC 1,204 ms
75,968 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:88:16: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
    while ('0'.toByte() > peek()) next()
               ^
Main.kt:89:16: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
    while ('0'.toByte() <= peek()) {
               ^
Main.kt:90:38: warning: 'toLong(): Long' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
      ans = ans * 10 + (peek() - '0'.toLong())
                                     ^

ソースコード

diff #

fun main(args: Array<String>) {
  val table = BooleanArray(2001, {true})
  val primes: MutableList<Int> = mutableListOf()
  for (i in 2..2000) {
    if (table[i]) {
      primes.add(i)
      for (j in 2*i..2000 step i) {
        table[j] = false
      }
    }
  }

  val rd = Reader()
  val N = rd.int()
  val A = IntArray(N)
  val zero = IntArray(N+1)
  for (i in 0..N-1) {
    A[i] = rd.int()
    zero[i+1] = zero[i] + (if (A[i] == 0) 1 else 0)
  }
  val Q = rd.int()
  val P = IntArray(Q)
  val L = IntArray(Q)
  val R = IntArray(Q)
  for (i in 0..Q-1) {
    P[i] = rd.int()
    L[i] = rd.int() - 1
    R[i] = rd.int()
  }
  val ruiseki = IntArray(N+1)
  val kotae = BooleanArray(Q, {true})
  for (p in primes) {
    ruiseki.fill(0)
    for (i in 0..N-1) {
      ruiseki[i+1] = ruiseki[i]
      if (A[i] == 0) continue
      while (A[i] % p == 0) {
        ruiseki[i+1]++;
        A[i] /= p
      }
    }
    for (i in 0..Q-1) {
      if (zero[R[i]] - zero[L[i]] > 0) {
        P[i] = 1
        continue
      }
      var k = 0
      while (P[i] % p == 0) {
        P[i] /= p
        k++
      }
      if (ruiseki[R[i]] - ruiseki[L[i]] < k) kotae[i] = false
    }
  }
  for (i in 0..Q-1) {
    if (P[i] != 1) kotae[i] = false
    println(if (kotae[i]) "Yes" else "NO")
  }
}

class Reader {
  var buf: ByteArray = ByteArray(5000000)
  var k: Int = 0
  var n: Int = 0

  init {
    check()
  }

  private fun check() {
    if (k == n) {
      n = System.`in`.read(buf)
      k = 0
    }
  }

  private fun peek(): Byte {
    return buf[k]
  }

  private fun next() {
    k++
    check()
  }

  fun long(): Long {
    var ans: Long = 0
    while ('0'.toByte() > peek()) next()
    while ('0'.toByte() <= peek()) {
      ans = ans * 10 + (peek() - '0'.toLong())
      next() 
    }
    return ans
  }

  fun int(): Int {
    return long().toInt()
  }
}
0