結果

問題 No.1617 Palindrome Removal
ユーザー 👑 箱
提出日時 2021-07-22 21:32:32
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 494 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 15,824 ms
コンパイル使用メモリ 416,440 KB
実行使用メモリ 58,064 KB
最終ジャッジ日時 2023-09-24 15:54:25
合計ジャッジ時間 25,789 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 476 ms
57,912 KB
testcase_01 AC 477 ms
57,800 KB
testcase_02 AC 490 ms
57,808 KB
testcase_03 AC 494 ms
57,916 KB
testcase_04 AC 481 ms
58,064 KB
testcase_05 AC 468 ms
57,764 KB
testcase_06 AC 379 ms
56,252 KB
testcase_07 AC 373 ms
56,088 KB
testcase_08 AC 287 ms
52,784 KB
testcase_09 AC 290 ms
52,728 KB
testcase_10 AC 479 ms
57,664 KB
testcase_11 AC 476 ms
57,920 KB
testcase_12 AC 485 ms
58,012 KB
testcase_13 AC 478 ms
57,860 KB
testcase_14 AC 327 ms
57,072 KB
testcase_15 AC 289 ms
52,780 KB
testcase_16 AC 331 ms
56,904 KB
testcase_17 AC 326 ms
56,924 KB
testcase_18 AC 324 ms
56,852 KB
testcase_19 AC 321 ms
56,956 KB
testcase_20 AC 323 ms
57,088 KB
testcase_21 AC 331 ms
57,088 KB
testcase_22 AC 328 ms
56,900 KB
testcase_23 AC 326 ms
57,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val s = nextLine()
    val t = s.reversed()
    if (s != t) {
        println(s.length)
    } else if (s.toCharArray().distinct().count() > 1) {
        if (s.length != 3) {
            println(s.length - 2)
        } else {
            println(-1)
        }
    } else if (s.length % 2 == 0) {
        println(0)
    } else {
        println(-1)
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve()
    writer.flush()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

fun next(): String {
    while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
    return st.nextToken()
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()
fun nextDouble() = next().toDouble()
// endregion
0