結果

問題 No.1362 [Zelkova 8th Tune] Black Sheep
ユーザー qszhu
提出日時 2022-10-07 16:54:48
言語 Kotlin
(2.1.0)
結果
AC  
実行時間 376 ms / 1,000 ms
コード長 728 bytes
コンパイル時間 13,733 ms
コンパイル使用メモリ 434,396 KB
実行使用メモリ 61,840 KB
最終ジャッジ日時 2024-06-11 23:54:05
合計ジャッジ時間 27,045 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import kotlin.system.exitProcess

val br = System.`in`.bufferedReader()

fun readLine(): String? = br.readLine()
fun readString() = readLine()!!

const val MAX_STACK_SIZE: Long = 128 * 1024 * 1024

fun main() {
    val thread = Thread(null, ::run, "solve", MAX_STACK_SIZE)
    thread.setUncaughtExceptionHandler { _, e -> e.printStackTrace(); exitProcess(1) }
    thread.start()
}

fun run() {
    val S = readString()
    output(solve(S))
}

fun solve(S: String): Pair<Int, Char> {
    if (S[0] == S[1]) {
        for (i in 2..S.lastIndex) if (S[i] != S[0]) return i + 1 to S[i]
    }
    if (S[0] == S.last()) return 2 to S[1]
    return 1 to S[0]
}

fun output(res: Pair<Int, Char>) = res.apply { println("$first $second") }
0