結果

問題 No.973 余興
ユーザー yakamotoyakamoto
提出日時 2020-01-18 16:53:35
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,127 ms / 4,000 ms
コード長 2,043 bytes
コンパイル時間 18,054 ms
コンパイル使用メモリ 432,232 KB
実行使用メモリ 145,584 KB
最終ジャッジ日時 2023-09-10 03:41:09
合計ジャッジ時間 63,454 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 991 ms
143,192 KB
testcase_01 AC 996 ms
143,060 KB
testcase_02 AC 997 ms
143,164 KB
testcase_03 AC 999 ms
143,256 KB
testcase_04 AC 1,006 ms
143,432 KB
testcase_05 AC 993 ms
143,232 KB
testcase_06 AC 997 ms
143,188 KB
testcase_07 AC 1,008 ms
143,056 KB
testcase_08 AC 995 ms
142,792 KB
testcase_09 AC 1,009 ms
143,172 KB
testcase_10 AC 971 ms
140,028 KB
testcase_11 AC 562 ms
82,188 KB
testcase_12 AC 566 ms
82,416 KB
testcase_13 AC 560 ms
82,872 KB
testcase_14 AC 560 ms
82,308 KB
testcase_15 AC 363 ms
55,732 KB
testcase_16 AC 367 ms
56,056 KB
testcase_17 AC 355 ms
56,104 KB
testcase_18 AC 359 ms
55,612 KB
testcase_19 AC 358 ms
56,008 KB
testcase_20 AC 353 ms
55,812 KB
testcase_21 AC 364 ms
55,688 KB
testcase_22 AC 361 ms
55,844 KB
testcase_23 AC 360 ms
55,664 KB
testcase_24 AC 369 ms
55,680 KB
testcase_25 AC 346 ms
55,132 KB
testcase_26 AC 362 ms
55,664 KB
testcase_27 AC 364 ms
55,956 KB
testcase_28 AC 371 ms
56,004 KB
testcase_29 AC 365 ms
55,776 KB
testcase_30 AC 1,065 ms
145,488 KB
testcase_31 AC 1,062 ms
145,220 KB
testcase_32 AC 1,066 ms
145,480 KB
testcase_33 AC 1,068 ms
145,584 KB
testcase_34 AC 1,027 ms
144,872 KB
testcase_35 AC 1,040 ms
145,140 KB
testcase_36 AC 1,032 ms
142,696 KB
testcase_37 AC 1,031 ms
142,368 KB
testcase_38 AC 1,046 ms
144,904 KB
testcase_39 AC 1,062 ms
145,020 KB
testcase_40 AC 302 ms
54,892 KB
testcase_41 AC 304 ms
52,668 KB
testcase_42 AC 302 ms
52,740 KB
testcase_43 AC 306 ms
53,136 KB
testcase_44 AC 304 ms
53,056 KB
testcase_45 AC 310 ms
53,196 KB
testcase_46 AC 988 ms
144,856 KB
testcase_47 AC 993 ms
144,812 KB
testcase_48 AC 980 ms
144,748 KB
testcase_49 AC 943 ms
136,364 KB
testcase_50 AC 1,001 ms
144,756 KB
testcase_51 AC 994 ms
144,840 KB
testcase_52 AC 1,102 ms
144,884 KB
testcase_53 AC 1,079 ms
142,516 KB
testcase_54 AC 1,116 ms
144,608 KB
testcase_55 AC 1,127 ms
144,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import kotlin.math.min

val MOD = 1_000_000_007

fun main() {
  val (N, X) = readInts()
  val A = readInts()

  val dpL = Array(N){IntArray(N - it + 1)}
  val dpR = Array(N){IntArray(it + 2)}
  val mxR = run {
    val res = IntArray(N)
    var sum = 0L
    var r = N - 1
    for (l in N - 1 downTo 0) {
      sum += A[l]
      while (r > l && sum > X) {
        sum -= A[r]
        r--
      }
      res[l] = r - l + 1
    }
    res
  }
  debug(mxR)
  val mxL = run {
    val res = IntArray(N)
    var sum = 0L
    var l = 0
    for (r in 0 until N) {
      sum += A[r]
      while (l < r && sum > X) {
        sum -= A[l]
        l++
      }
      res[r] = r - l + 1
    }
    res
  }
  debug(mxL)

  for (d in 1 until N) {
    for (l in 0 until N - d) {
      val r = l + d
      val llen = min(d, mxL[r])
      val lwin = dpL[l][d] - dpL[l][d-llen] < llen
      val rlen = min(d, mxR[l])
      val rwin = dpR[r][d] - dpR[r][d-rlen] < rlen
      val win = if (lwin or rwin) 1 else 0
//      debug{"$l $r $win"}
      dpL[l][d+1] = dpL[l][d] + win
      dpR[r][d+1] = dpR[r][d] + win
    }
  }

  debugDim(dpL)
  debugDim(dpR)

  val awin = dpL[0][N] - dpL[0][N - 1] == 1
  if (awin) println("A")
  else println("B")
}












































private val isDebug = try {
  // なんか本番でエラーでる
  System.getenv("MY_DEBUG") != null
} catch (t: Throwable) {
  false
}

private fun readLn() = readLine()!!
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }.toIntArray()
private fun readLongs() = readStrings().map { it.toLong() }.toLongArray()
private inline fun debug(msg: () -> String) {
  if (isDebug) System.err.println(msg())
}
private fun debug(a: LongArray) {
  debug{a.joinToString(" ")}
}
private fun debug(a: IntArray) {
  debug{a.joinToString(" ")}
}
private fun debug(a: BooleanArray) {
  debug{a.map{if(it) 1 else 0}.joinToString("")}
}
private fun debugDim(A: Array<IntArray>) {
  if (isDebug) {
    for (a in A) {
      debug(a)
    }
  }
}
0