結果
| 問題 | No.101 ぐるぐる!あみだくじ! |
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2019-09-30 02:15:30 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,943 bytes |
| 記録 | |
| コンパイル時間 | 14,421 ms |
| コンパイル使用メモリ | 453,188 KB |
| 実行使用メモリ | 98,588 KB |
| 最終ジャッジ日時 | 2024-10-03 04:49:24 |
| 合計ジャッジ時間 | 22,896 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 11 TLE * 1 -- * 25 |
コンパイルメッセージ
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()
^
ソースコード
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
}
バカらっく