結果

問題 No.6 使いものにならないハッシュ
ユーザー バカらっくバカらっく
提出日時 2019-08-29 08:47:49
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 364 ms / 5,000 ms
コード長 1,357 bytes
コンパイル時間 14,379 ms
コンパイル使用メモリ 436,524 KB
実行使用メモリ 53,540 KB
最終ジャッジ日時 2024-09-16 16:51:25
合計ジャッジ時間 26,364 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 286 ms
50,460 KB
testcase_01 AC 283 ms
50,876 KB
testcase_02 AC 353 ms
53,540 KB
testcase_03 AC 313 ms
51,376 KB
testcase_04 AC 314 ms
51,404 KB
testcase_05 AC 346 ms
51,680 KB
testcase_06 AC 340 ms
52,264 KB
testcase_07 AC 312 ms
51,940 KB
testcase_08 AC 347 ms
52,352 KB
testcase_09 AC 314 ms
52,292 KB
testcase_10 AC 288 ms
50,816 KB
testcase_11 AC 314 ms
51,412 KB
testcase_12 AC 344 ms
52,480 KB
testcase_13 AC 313 ms
52,148 KB
testcase_14 AC 312 ms
52,020 KB
testcase_15 AC 343 ms
52,400 KB
testcase_16 AC 332 ms
52,592 KB
testcase_17 AC 348 ms
52,968 KB
testcase_18 AC 351 ms
53,268 KB
testcase_19 AC 346 ms
52,820 KB
testcase_20 AC 351 ms
52,500 KB
testcase_21 AC 305 ms
51,128 KB
testcase_22 AC 345 ms
52,884 KB
testcase_23 AC 364 ms
52,636 KB
testcase_24 AC 352 ms
52,652 KB
testcase_25 AC 349 ms
52,192 KB
testcase_26 AC 361 ms
53,108 KB
testcase_27 AC 357 ms
52,620 KB
testcase_28 AC 352 ms
51,956 KB
testcase_29 AC 345 ms
53,140 KB
testcase_30 AC 357 ms
53,052 KB
testcase_31 AC 357 ms
52,588 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>){
         ^

ソースコード

diff #

fun main(args: Array<String>){
    val k = readLine()!!.toInt()
    val n = readLine()!!.toInt()
    val primeList = getPrimeList(n).filter { it >= k }
    val convList = primeList.map { getConv(it) }

    var fromIdx = 0
    var maxLength = 0
    var maxFromIdx = 0
    val dic = mutableMapOf<Int,Boolean>()
    for(i in convList.indices) {
        if(dic.containsKey(convList[i])) {
            for(j in fromIdx..i) {
                dic.remove(convList[j])
                if(convList[j] == convList[i]) {
                    fromIdx = j+1
                    break
                }
            }
        }
        dic[convList[i]] = true
        val len = i - fromIdx + 1
        if(len >= maxLength) {
            maxLength = len
            maxFromIdx = fromIdx
        }
    }
    println(primeList[maxFromIdx])
}

fun getConv(inNum: Int):Int {
    if(inNum < 10) {
        return inNum
    }
    val outNum = getConv((inNum/10) + (inNum%10))
    return outNum
}

fun getPrimeList(maxNum:Int):List<Int> {
    val flags = arrayOfNulls<Boolean>(maxNum+1)
    val list = mutableListOf<Int>()
    for (i in 2..maxNum) {
        if(flags[i] != null && flags[i]!!) {
            continue
        }
        val maxIndex = maxNum/i
        for(j in 1..maxIndex) {
            flags[i*j] = true
        }
        list.add(i)
    }
    return list.toList()
}
0