結果

問題 No.6 使いものにならないハッシュ
ユーザー バカらっくバカらっく
提出日時 2019-08-29 08:47:49
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 356 ms / 5,000 ms
コード長 1,357 bytes
コンパイル時間 17,587 ms
コンパイル使用メモリ 419,536 KB
実行使用メモリ 57,312 KB
最終ジャッジ日時 2023-10-14 23:19:05
合計ジャッジ時間 29,417 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 280 ms
52,412 KB
testcase_01 AC 281 ms
52,776 KB
testcase_02 AC 355 ms
57,312 KB
testcase_03 AC 312 ms
52,388 KB
testcase_04 AC 321 ms
52,396 KB
testcase_05 AC 347 ms
52,552 KB
testcase_06 AC 356 ms
52,716 KB
testcase_07 AC 313 ms
52,484 KB
testcase_08 AC 343 ms
52,596 KB
testcase_09 AC 312 ms
52,440 KB
testcase_10 AC 281 ms
52,328 KB
testcase_11 AC 320 ms
52,328 KB
testcase_12 AC 347 ms
52,904 KB
testcase_13 AC 320 ms
54,248 KB
testcase_14 AC 314 ms
52,288 KB
testcase_15 AC 345 ms
52,836 KB
testcase_16 AC 332 ms
52,600 KB
testcase_17 AC 348 ms
54,724 KB
testcase_18 AC 354 ms
54,748 KB
testcase_19 AC 346 ms
54,612 KB
testcase_20 AC 345 ms
52,804 KB
testcase_21 AC 300 ms
52,524 KB
testcase_22 AC 344 ms
54,696 KB
testcase_23 AC 343 ms
53,032 KB
testcase_24 AC 342 ms
54,644 KB
testcase_25 AC 347 ms
52,908 KB
testcase_26 AC 350 ms
54,644 KB
testcase_27 AC 347 ms
52,652 KB
testcase_28 AC 351 ms
52,872 KB
testcase_29 AC 352 ms
54,844 KB
testcase_30 AC 350 ms
54,700 KB
testcase_31 AC 346 ms
54,884 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