結果

問題 No.1501 酔歩
ユーザー yakamotoyakamoto
提出日時 2021-05-08 00:17:38
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 3,887 bytes
コンパイル時間 16,471 ms
コンパイル使用メモリ 464,292 KB
実行使用メモリ 88,892 KB
最終ジャッジ日時 2024-09-15 12:23:53
合計ジャッジ時間 49,182 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 287 ms
49,864 KB
testcase_01 AC 279 ms
49,700 KB
testcase_02 AC 276 ms
49,948 KB
testcase_03 AC 277 ms
49,844 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 479 ms
77,300 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 501 ms
83,908 KB
testcase_46 AC 509 ms
85,596 KB
testcase_47 AC 480 ms
76,172 KB
testcase_48 AC 515 ms
77,376 KB
testcase_49 AC 539 ms
85,452 KB
testcase_50 AC 518 ms
77,284 KB
testcase_51 AC 504 ms
77,288 KB
testcase_52 AC 504 ms
77,060 KB
testcase_53 WA -
testcase_54 AC 283 ms
49,856 KB
testcase_55 AC 276 ms
49,924 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:38:37: warning: unchecked cast: Array<Frac?> to Array<Frac>
      val L = arrayOfNulls<Frac>(N) as Array<Frac>
                                    ^
Main.kt:156:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun debug(a: LongArray) {
          ^
Main.kt:160:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun debug(a: IntArray) {
          ^
Main.kt:164:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun debug(a: BooleanArray) {
          ^
Main.kt:168:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString("")}
          ^
Main.kt:170:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun debugDim(A: Array<LongArray>) {
          ^
Main.kt:177:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun debugDim(A: Array<IntArray>) {
          ^
Main.kt:184:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun debugDim(A: Array<BooleanArray>) {
          ^
Main.kt:201:11: warning: expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types
  private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()}
          ^

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.lang.AssertionError
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007

tailrec fun gcd(a: Long, b: Long): Long {
  if (b == 0L) return abs(a)
  return gcd(b, a % b)
}
/**
 * (0, 1) 0, 1はなし
 */
data class Frac(val a: Long, val b: Long) {
  operator fun times(f: Frac) = frac(a*f.a, b*f.b)
  operator fun div(f: Frac) = frac(a*f.b, b*f.a)
  fun comp() = frac(b - a, b)
}

fun frac(a0: Long, b0: Long) = run {
  val g = gcd(a0, b0)
  Frac(a0/g, b0/g)
}

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  private val reader = BufferedReader(InputStreamReader(stream), 32768)

  fun solve() {
    val N = ni()
    val K = ni() - 1
    val A = nal(N)
    fun create(A: LongArray) = run {
      val L = arrayOfNulls<Frac>(N) as Array<Frac>
      L[0] = frac(1, 1)
      L[N - 1] = frac(0, 1)
      for (i in 1 until N - 1) {
        val pl = frac(A[i - 1], A[i - 1] + A[i + 1])
        val a = pl*L[i - 1]
        val r = L[i - 1].comp()*pl
        L[i] = a / r.comp()
      }
      L
    }
    val L = create(A)
    debug{"${L.joinToString(" ")}"}

    val ans = when(K) {
      0 -> "0"
      N - 1 -> "1/1"
      else -> {
        var ans = frac(1, 1)
        for (i in K until N - 1) {
          ans *= L[i].comp()
        }
        "${ans.a}/${ans.b}"
      }
    }
    out.println(ans)
  }













































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

  private var tokenizer: StringTokenizer? = null
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return IntArray(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  /**
   * コーナーケースでエラー出たりするので、debug(dp[1])のように添え字付きの場合はdebug{}をつかうこと
   */
  private inline fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private inline fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private inline fun debug(a: BooleanArray) {
    debug { toString(a) }
  }

  private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString("")}

  private inline fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private inline fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private inline fun debugDim(A: Array<BooleanArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }

  private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()}
  private inline fun assert(b: Boolean, f: () -> String) = run{if (!b) throw AssertionError(f())}
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}
0