結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー バカらっくバカらっく
提出日時 2019-09-30 02:56:27
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 438 ms / 5,000 ms
コード長 1,309 bytes
コンパイル時間 15,920 ms
コンパイル使用メモリ 457,960 KB
実行使用メモリ 59,868 KB
最終ジャッジ日時 2024-04-14 07:42:47
合計ジャッジ時間 35,166 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 338 ms
56,976 KB
testcase_01 AC 377 ms
57,604 KB
testcase_02 AC 368 ms
57,584 KB
testcase_03 AC 366 ms
59,368 KB
testcase_04 AC 358 ms
59,344 KB
testcase_05 AC 383 ms
59,624 KB
testcase_06 AC 368 ms
57,312 KB
testcase_07 AC 391 ms
57,344 KB
testcase_08 AC 386 ms
57,500 KB
testcase_09 AC 396 ms
59,584 KB
testcase_10 AC 394 ms
59,636 KB
testcase_11 AC 405 ms
59,720 KB
testcase_12 AC 421 ms
59,616 KB
testcase_13 AC 420 ms
59,732 KB
testcase_14 AC 414 ms
59,692 KB
testcase_15 AC 413 ms
59,648 KB
testcase_16 AC 420 ms
59,764 KB
testcase_17 AC 413 ms
59,728 KB
testcase_18 AC 409 ms
59,688 KB
testcase_19 AC 406 ms
59,592 KB
testcase_20 AC 402 ms
59,704 KB
testcase_21 AC 426 ms
59,596 KB
testcase_22 AC 415 ms
59,708 KB
testcase_23 AC 431 ms
59,612 KB
testcase_24 AC 406 ms
59,636 KB
testcase_25 AC 415 ms
59,588 KB
testcase_26 AC 425 ms
59,724 KB
testcase_27 AC 414 ms
59,712 KB
testcase_28 AC 404 ms
59,652 KB
testcase_29 AC 407 ms
59,584 KB
testcase_30 AC 399 ms
59,716 KB
testcase_31 AC 424 ms
59,868 KB
testcase_32 AC 421 ms
59,712 KB
testcase_33 AC 438 ms
59,624 KB
testcase_34 AC 370 ms
57,328 KB
testcase_35 AC 358 ms
57,276 KB
testcase_36 AC 348 ms
57,316 KB
testcase_37 AC 386 ms
59,408 KB
testcase_38 AC 377 ms
59,504 KB
testcase_39 AC 375 ms
59,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^

ソースコード

diff #

import kotlin.math.max

fun main(arr:Array<String>) {
    val columnCount = readLine()!!.toInt()
    val barCount = readLine()!!.toInt()
    val barMap = (0 until barCount).map { readLine()!!.split(" ").map { it.toInt() - 1 } }

    val moveTo = (0 until columnCount).map {
        getGoal(it, barMap)
    }

    var cycleList = (0 until columnCount).map { 0 }
    var numList = (0 until columnCount).map { it }
    for(i in (1..100)) {
        var tmp = numList.withIndex().sortedBy { moveTo[it.index] }.map { it.value }
        numList = tmp
        cycleList = cycleList.withIndex().map { if(it.value > 0) it.value else(if (numList[it.index] == it.index) i else 0) }
    }

    val ans = cycleList.map { it.toLong() }.reduce { acc, i -> getMinKoubai(acc, i) }
    println(ans)
}

fun getMinKoubai(num1:Long, num2:Long):Long {
    val kouyaku = getMaxKouyaku(num1, num2)
    return num1 * num2 / kouyaku
}

fun getMaxKouyaku(num1:Long, num2:Long):Long {
    if(num1 % num2 == 0L) {
        return num2
    }
    return getMaxKouyaku(num2, num1%num2)
}

fun getGoal(column:Int, barMap:List<List<Int>>):Int {
    var current = column
    for((f,t) in barMap) {
        if(f == current) {
            current = t
        } else if(current == t) {
            current = f
        }
    }
    return current
}


0