結果

問題 No.273 回文分解
ユーザー javyjavy
提出日時 2015-11-28 03:31:47
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 1,783 bytes
コンパイル時間 15,297 ms
コンパイル使用メモリ 422,248 KB
実行使用メモリ 53,196 KB
最終ジャッジ日時 2023-08-12 15:56:14
合計ジャッジ時間 25,836 ms
ジャッジサーバーID
(参考情報)
judge7 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 283 ms
53,044 KB
testcase_01 AC 281 ms
52,776 KB
testcase_02 AC 280 ms
52,828 KB
testcase_03 AC 281 ms
52,784 KB
testcase_04 AC 276 ms
52,708 KB
testcase_05 AC 279 ms
52,856 KB
testcase_06 AC 279 ms
53,040 KB
testcase_07 AC 278 ms
52,736 KB
testcase_08 AC 277 ms
52,764 KB
testcase_09 AC 283 ms
53,196 KB
testcase_10 AC 285 ms
53,092 KB
testcase_11 AC 289 ms
52,828 KB
testcase_12 AC 286 ms
53,012 KB
testcase_13 AC 284 ms
52,712 KB
testcase_14 AC 280 ms
52,732 KB
testcase_15 AC 281 ms
52,780 KB
testcase_16 AC 284 ms
52,904 KB
testcase_17 AC 280 ms
52,828 KB
testcase_18 AC 279 ms
52,756 KB
testcase_19 AC 280 ms
52,860 KB
testcase_20 AC 276 ms
52,864 KB
testcase_21 AC 284 ms
52,736 KB
testcase_22 AC 279 ms
52,776 KB
testcase_23 AC 279 ms
52,840 KB
testcase_24 AC 278 ms
52,736 KB
testcase_25 AC 281 ms
52,756 KB
testcase_26 AC 284 ms
52,876 KB
testcase_27 AC 286 ms
53,028 KB
testcase_28 AC 288 ms
53,152 KB
testcase_29 AC 280 ms
52,788 KB
testcase_30 AC 277 ms
53,028 KB
testcase_31 AC 277 ms
52,864 KB
testcase_32 AC 275 ms
53,012 KB
testcase_33 AC 284 ms
52,780 KB
testcase_34 AC 280 ms
52,708 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:6:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:49:14: warning: variable 'ch' is never used
    for ((i, ch) in inputStr.withIndex()) {
             ^

ソースコード

diff #

package Yukicoder

/**
 * Created by hichikawa on 2015/11/12.
 */
fun main(args: Array<String>) {
    fun readLineLongArray(): List<Long> {
        val str = readLine() as String
        val arrStr = str.split(" ")
        val ret = arrStr.map { it.toLong() }
        return ret
    }

    fun readLineLong(): Long {
        val str = readLine() as String
        return str.toLong()
    }

    fun readLineInt(): Int {
        val str = readLine() as String
        return str.toInt()
    }

    fun readLineIntArray() : List<Int> {
        val str = readLine() as String
        val arrStr = str.split(" ")
        val ret = arrStr.map { it.toInt() }
        return ret
    }

    fun readLineDoubleArray(): List<Double> {
        val str = readLine() as String
        val arrStr = str.split(" ")
        val ret = arrStr.map { it.toDouble() }
        return ret
    }

    fun checkKai(str : String , startIndex : Int, endIndex : Int) : Boolean{
        for (i in 0..((endIndex-startIndex)/2)) {
            if (str.get(startIndex+i) != str.get(endIndex-i)) {
                return false
            }
        }
        return true
    }

    val inputStr = readLine() as String
    var maxI = Int.MIN_VALUE
    for ((i, ch) in inputStr.withIndex()) {
//    var lastIndex = inputStr.length
        var lastIndex = if (i != 0) inputStr.length else inputStr.length-1
        do {
            lastIndex = inputStr.lastIndexOf(inputStr[i], lastIndex-1)
            if (checkKai(inputStr, i, lastIndex)) {
//                println((lastIndex-i).toString() + " " + i + " " + lastIndex)
                if (maxI <= (lastIndex-i)) {
                    maxI = lastIndex-i+1
                }
                break
            }
        } while (i < lastIndex)
    }
    println(maxI)
}
0