結果

問題 No.428 小数から逃げる夢
ユーザー nobigomunobigomu
提出日時 2018-06-07 12:43:55
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 334 ms / 1,000 ms
コード長 1,960 bytes
コンパイル時間 11,834 ms
コンパイル使用メモリ 447,348 KB
実行使用メモリ 56,952 KB
最終ジャッジ日時 2024-04-30 18:48:49
合計ジャッジ時間 41,096 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 271 ms
56,752 KB
testcase_01 AC 265 ms
56,712 KB
testcase_02 AC 266 ms
56,796 KB
testcase_03 AC 266 ms
56,720 KB
testcase_04 AC 264 ms
56,836 KB
testcase_05 AC 266 ms
56,708 KB
testcase_06 AC 272 ms
56,856 KB
testcase_07 AC 267 ms
56,804 KB
testcase_08 AC 261 ms
56,740 KB
testcase_09 AC 260 ms
56,764 KB
testcase_10 AC 264 ms
56,812 KB
testcase_11 AC 267 ms
56,828 KB
testcase_12 AC 265 ms
56,816 KB
testcase_13 AC 268 ms
56,728 KB
testcase_14 AC 274 ms
56,716 KB
testcase_15 AC 265 ms
56,792 KB
testcase_16 AC 267 ms
56,848 KB
testcase_17 AC 269 ms
56,844 KB
testcase_18 AC 278 ms
56,720 KB
testcase_19 AC 264 ms
56,716 KB
testcase_20 AC 286 ms
56,808 KB
testcase_21 AC 269 ms
56,812 KB
testcase_22 AC 261 ms
56,752 KB
testcase_23 AC 259 ms
56,748 KB
testcase_24 AC 264 ms
56,816 KB
testcase_25 AC 262 ms
56,852 KB
testcase_26 AC 257 ms
56,716 KB
testcase_27 AC 264 ms
56,840 KB
testcase_28 AC 260 ms
56,720 KB
testcase_29 AC 271 ms
56,840 KB
testcase_30 AC 267 ms
56,772 KB
testcase_31 AC 265 ms
56,812 KB
testcase_32 AC 264 ms
56,840 KB
testcase_33 AC 260 ms
56,884 KB
testcase_34 AC 262 ms
56,780 KB
testcase_35 AC 262 ms
56,832 KB
testcase_36 AC 266 ms
56,720 KB
testcase_37 AC 257 ms
56,828 KB
testcase_38 AC 261 ms
56,744 KB
testcase_39 AC 267 ms
56,864 KB
testcase_40 AC 267 ms
56,768 KB
testcase_41 AC 260 ms
56,864 KB
testcase_42 AC 270 ms
56,824 KB
testcase_43 AC 270 ms
56,840 KB
testcase_44 AC 270 ms
56,904 KB
testcase_45 AC 266 ms
56,808 KB
testcase_46 AC 267 ms
56,732 KB
testcase_47 AC 269 ms
56,720 KB
testcase_48 AC 275 ms
56,848 KB
testcase_49 AC 275 ms
56,768 KB
testcase_50 AC 269 ms
56,608 KB
testcase_51 AC 273 ms
56,848 KB
testcase_52 AC 268 ms
56,736 KB
testcase_53 AC 272 ms
56,820 KB
testcase_54 AC 264 ms
56,848 KB
testcase_55 AC 261 ms
56,832 KB
testcase_56 AC 266 ms
56,840 KB
testcase_57 AC 271 ms
56,836 KB
testcase_58 AC 264 ms
56,712 KB
testcase_59 AC 274 ms
56,760 KB
testcase_60 AC 266 ms
56,844 KB
testcase_61 AC 261 ms
56,868 KB
testcase_62 AC 268 ms
56,764 KB
testcase_63 AC 277 ms
56,736 KB
testcase_64 AC 268 ms
56,800 KB
testcase_65 AC 262 ms
56,816 KB
testcase_66 AC 267 ms
56,816 KB
testcase_67 AC 268 ms
56,824 KB
testcase_68 AC 269 ms
56,864 KB
testcase_69 AC 268 ms
56,860 KB
testcase_70 AC 334 ms
56,836 KB
testcase_71 AC 268 ms
56,820 KB
testcase_72 AC 262 ms
56,740 KB
testcase_73 AC 271 ms
56,704 KB
testcase_74 AC 270 ms
56,828 KB
testcase_75 AC 278 ms
56,868 KB
testcase_76 AC 273 ms
56,708 KB
testcase_77 AC 279 ms
56,832 KB
testcase_78 AC 280 ms
56,752 KB
testcase_79 AC 264 ms
56,736 KB
testcase_80 AC 276 ms
56,952 KB
testcase_81 AC 276 ms
56,708 KB
testcase_82 AC 259 ms
56,824 KB
testcase_83 AC 260 ms
56,752 KB
testcase_84 AC 268 ms
56,816 KB
testcase_85 AC 267 ms
56,720 KB
testcase_86 AC 268 ms
56,724 KB
testcase_87 AC 267 ms
56,768 KB
testcase_88 AC 274 ms
56,732 KB
testcase_89 AC 265 ms
56,740 KB
testcase_90 AC 261 ms
56,812 KB
testcase_91 AC 265 ms
56,784 KB
testcase_92 AC 270 ms
56,816 KB
testcase_93 AC 261 ms
56,824 KB
testcase_94 AC 267 ms
56,748 KB
testcase_95 AC 264 ms
56,784 KB
testcase_96 AC 270 ms
56,828 KB
testcase_97 AC 268 ms
56,844 KB
testcase_98 AC 278 ms
56,708 KB
testcase_99 AC 276 ms
56,808 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:50:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

val D = "1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991"

fun f(n:Int): String {
    tailrec fun iter(i: Int, c: Int, sb: StringBuilder) {
        if (i>=0) {
            val t = n*D.slice(i..i).toInt()+c
            sb.insert(0,(t%10).toString())
            return iter(i-1, t/10, sb)
        } else {
            if (c!=0) { sb.insert(0,c.toString()) }
        }
    }
    val sb = StringBuilder(D.length+2)
    val t = n*D.slice(D.length-1..D.length-1).toInt()
    sb.insert(0,(t%10).toString())
    iter(D.length-2,t/10,sb)
    if (sb.length==D.length) sb.insert(0,"0.") else sb.insert(sb.length-D.length,".")
    return sb.toString()
}

fun g(m: Int, n: Int): String {
    fun f(a: Int, b: Int, c: Int) = if (a%10+b%10+c>9) 1 else 0
    tailrec fun iter(i: Int, c: Int, c1: Int, c2: Int, t2: Int, sb: StringBuilder) {
        if (i>=0) {
            val t = D.slice(i..i).toInt()
            val t1 = n*t+c1
            sb.insert(0,((t2+t1+c)%10).toString())
            iter(i-1, f(t2,t1,c), t1/10, (m*t+c2)/10, m*t+c2, sb)
        } else {
            sb.insert(0,(t2+c1+c).toString())
        }
    }
    val sb = StringBuilder(D.length+3)
    var t = D.slice(D.length-1..D.length-1).toInt()
    var t1 = n*t
    val t2 = m*t
    val c1 = t1/10
    val c2 = t2/10
    sb.insert(0,(t1%10).toString())

    t = D.slice(D.length-2..D.length-2).toInt()
    t1 = n*t+c1
    sb.insert(0,((t1+t2)%10).toString())
    iter(D.length-3, f(t2,t1,0), t1/10, (m*t+c2)/10, m*t+c2, sb)

    sb.insert(sb.length-D.length,".")
    return sb.toString()
}

fun main(args: Array<String>) {
    val s = readLine()!!
    when (s.length) {
        1 -> println(f(s.toInt()))
        2 -> println(g(s.slice(0..0).toInt(), s.slice(1..1).toInt()))
        else -> println(D.slice(0..1).plus(".").plus(D.slice(2..D.length-1)))
    }
}
0