結果

問題 No.273 回文分解
ユーザー javyjavy
提出日時 2015-11-28 03:31:47
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 1,783 bytes
コンパイル時間 13,651 ms
コンパイル使用メモリ 451,932 KB
実行使用メモリ 58,640 KB
最終ジャッジ日時 2024-04-30 10:33:25
合計ジャッジ時間 24,429 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 289 ms
56,716 KB
testcase_01 AC 286 ms
56,732 KB
testcase_02 AC 288 ms
56,620 KB
testcase_03 AC 281 ms
56,796 KB
testcase_04 AC 285 ms
56,620 KB
testcase_05 AC 288 ms
56,736 KB
testcase_06 AC 294 ms
56,644 KB
testcase_07 AC 292 ms
56,780 KB
testcase_08 AC 293 ms
56,728 KB
testcase_09 AC 294 ms
56,736 KB
testcase_10 AC 289 ms
56,684 KB
testcase_11 AC 291 ms
56,608 KB
testcase_12 AC 296 ms
56,544 KB
testcase_13 AC 292 ms
56,696 KB
testcase_14 AC 294 ms
58,640 KB
testcase_15 AC 293 ms
56,612 KB
testcase_16 AC 292 ms
56,552 KB
testcase_17 AC 296 ms
56,716 KB
testcase_18 AC 293 ms
56,772 KB
testcase_19 AC 319 ms
56,736 KB
testcase_20 AC 289 ms
56,788 KB
testcase_21 AC 289 ms
56,620 KB
testcase_22 AC 291 ms
56,644 KB
testcase_23 AC 290 ms
56,760 KB
testcase_24 AC 289 ms
56,552 KB
testcase_25 AC 300 ms
56,568 KB
testcase_26 AC 293 ms
56,660 KB
testcase_27 AC 297 ms
56,768 KB
testcase_28 AC 294 ms
56,652 KB
testcase_29 AC 291 ms
56,764 KB
testcase_30 AC 291 ms
56,640 KB
testcase_31 AC 295 ms
56,756 KB
testcase_32 AC 298 ms
56,724 KB
testcase_33 AC 292 ms
56,720 KB
testcase_34 AC 292 ms
56,620 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