結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー バカらっくバカらっく
提出日時 2019-09-30 02:15:30
言語 Kotlin
(1.9.10)
結果
TLE  
実行時間 -
コード長 1,943 bytes
コンパイル時間 16,718 ms
コンパイル使用メモリ 430,944 KB
実行使用メモリ 65,572 KB
最終ジャッジ日時 2023-07-26 18:10:09
合計ジャッジ時間 27,816 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 294 ms
52,804 KB
testcase_01 AC 312 ms
53,464 KB
testcase_02 AC 312 ms
53,244 KB
testcase_03 AC 336 ms
55,392 KB
testcase_04 AC 306 ms
53,108 KB
testcase_05 AC 322 ms
53,456 KB
testcase_06 AC 294 ms
53,228 KB
testcase_07 AC 317 ms
53,268 KB
testcase_08 AC 319 ms
53,348 KB
testcase_09 AC 344 ms
53,408 KB
testcase_10 AC 341 ms
53,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^
Main.kt:25:42: warning: no cast needed
    val cycleList = groupList.map { null as Int? }.toTypedArray()
                                         ^

ソースコード

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)
    }

    val groupList = mutableListOf<List<Int>>()
    var subList = mutableListOf<Int>()
    (0 until columnCount).forEach { a->
        subList.add(a)
        barMap.find { it[0] == a }?: run {
            groupList.add(subList)
            subList = mutableListOf()
        }
    }
    if(subList.isNotEmpty()) {
        groupList.add(subList)
    }

    val cycleList = groupList.map { null as Int? }.toTypedArray()

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

        for(j in groupList.indices) {
            if(cycleList[j] != null) {
                continue
            }
            if(numList.withIndex().filter { it.index in groupList[j] }.all { it.index == it.value }) {
                cycleList[j] = i
            }
        }
        if(cycleList.all { it != null }) {
            break
        }
    }

    val ans = cycleList.filter { it != null }.map { it!!.toLong() }.reduce { acc, i -> getMinKoubai(acc.toLong(), i.toLong()) }
    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