結果
問題 | No.973 余興 |
ユーザー | yakamoto |
提出日時 | 2020-01-18 15:20:12 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 3,081 ms / 4,000 ms |
コード長 | 3,242 bytes |
コンパイル時間 | 18,298 ms |
コンパイル使用メモリ | 465,228 KB |
実行使用メモリ | 146,156 KB |
最終ジャッジ日時 | 2024-06-27 15:11:09 |
合計ジャッジ時間 | 115,644 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,246 ms
145,544 KB |
testcase_01 | AC | 2,191 ms
145,648 KB |
testcase_02 | AC | 2,209 ms
145,468 KB |
testcase_03 | AC | 2,161 ms
145,436 KB |
testcase_04 | AC | 2,609 ms
145,624 KB |
testcase_05 | AC | 2,263 ms
145,664 KB |
testcase_06 | AC | 2,209 ms
145,536 KB |
testcase_07 | AC | 2,168 ms
145,868 KB |
testcase_08 | AC | 2,290 ms
145,684 KB |
testcase_09 | AC | 2,171 ms
145,688 KB |
testcase_10 | AC | 2,342 ms
145,768 KB |
testcase_11 | AC | 1,168 ms
105,212 KB |
testcase_12 | AC | 1,169 ms
105,324 KB |
testcase_13 | AC | 1,163 ms
104,860 KB |
testcase_14 | AC | 1,172 ms
105,072 KB |
testcase_15 | AC | 453 ms
55,104 KB |
testcase_16 | AC | 453 ms
55,396 KB |
testcase_17 | AC | 431 ms
54,152 KB |
testcase_18 | AC | 443 ms
54,804 KB |
testcase_19 | AC | 436 ms
54,728 KB |
testcase_20 | AC | 433 ms
54,380 KB |
testcase_21 | AC | 456 ms
55,404 KB |
testcase_22 | AC | 455 ms
55,288 KB |
testcase_23 | AC | 446 ms
54,900 KB |
testcase_24 | AC | 443 ms
55,100 KB |
testcase_25 | AC | 420 ms
53,448 KB |
testcase_26 | AC | 432 ms
54,312 KB |
testcase_27 | AC | 464 ms
55,848 KB |
testcase_28 | AC | 443 ms
54,672 KB |
testcase_29 | AC | 450 ms
54,516 KB |
testcase_30 | AC | 2,844 ms
145,816 KB |
testcase_31 | AC | 2,777 ms
145,768 KB |
testcase_32 | AC | 2,735 ms
145,692 KB |
testcase_33 | AC | 2,807 ms
145,744 KB |
testcase_34 | AC | 2,808 ms
145,728 KB |
testcase_35 | AC | 2,825 ms
145,812 KB |
testcase_36 | AC | 2,738 ms
145,796 KB |
testcase_37 | AC | 2,837 ms
145,532 KB |
testcase_38 | AC | 2,706 ms
145,796 KB |
testcase_39 | AC | 2,766 ms
145,604 KB |
testcase_40 | AC | 319 ms
51,680 KB |
testcase_41 | AC | 322 ms
51,868 KB |
testcase_42 | AC | 320 ms
51,764 KB |
testcase_43 | AC | 322 ms
51,904 KB |
testcase_44 | AC | 322 ms
51,804 KB |
testcase_45 | AC | 335 ms
51,908 KB |
testcase_46 | AC | 2,680 ms
145,724 KB |
testcase_47 | AC | 2,719 ms
145,420 KB |
testcase_48 | AC | 2,689 ms
145,724 KB |
testcase_49 | AC | 2,534 ms
146,156 KB |
testcase_50 | AC | 2,714 ms
145,840 KB |
testcase_51 | AC | 2,794 ms
145,804 KB |
testcase_52 | AC | 2,856 ms
145,520 KB |
testcase_53 | AC | 2,827 ms
145,408 KB |
testcase_54 | AC | 2,822 ms
145,804 KB |
testcase_55 | AC | 3,081 ms
145,712 KB |
コンパイルメッセージ
Main.kt:82:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types private inline fun f(a: Boolean, b: Boolean) = a and b ^
ソースコード
import kotlin.math.max import kotlin.math.min val MOD = 1_000_000_007 fun main() { val (N, X) = readInts() val A = readInts() val dpL = Array(N){SegmentTree(N - it, true)} val dpR = Array(N){SegmentTree(it + 1, true)} for (i in 0 until N) { // 1個だけ残ってる場合はlose dpL[i].update(0, false) dpR[i].update(0, false) } 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 (len in 2 until N + 1) { for (l in 0 until N - len + 1) { val r = l + len - 1 val win = !dpL[l].query(max(0, len-mxL[r]-1), len-1) or !dpR[r].query(max(0, len-mxR[l]-1), len-1) debug{"$l $r $win"} dpL[l].update(len - 1, win) dpR[r].update(len - 1, win) } } if(isDebug) { for (l in 0 until N) { val flags = mutableListOf<Boolean>() for (r in l until N) { val len = r-l assert(dpL[l].query(len, len+1) == dpR[r].query(len, len+1)) flags.add(dpR[r].query(len, len+1)) } debug(flags.toBooleanArray()) } } if (dpL[0].query(N-1, N)) println("A") else println("B") } class SegmentTree(n: Int, val zero: Boolean) { private val N = if (Integer.highestOneBit(n) == n) n else Integer.highestOneBit(n) shl 1 private val dat = BooleanArray(2 * N){zero} private inline fun f(a: Boolean, b: Boolean) = a and b fun update(i: Int, a: Boolean) { var ix = i + N dat[ix] = a while(ix > 1) { dat[ix shr 1] = f(dat[ix], dat[ix xor 1]) ix = ix shr 1 } } /** * [a, b) */ fun query(a: Int, b: Int): Boolean { var res: Boolean = zero var left = a + N var right = b - 1 + N while(left <= right) { if ((left and 1) == 1) res = f(res, dat[left]) if ((right and 1) == 0) res = f(res, dat[right]) left = (left + 1) shr 1 // 右の子供なら右の親に移動 right = (right - 1) shr 1 // 左の子供なら左の親に移動 } return res } } 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) } } }