結果

問題 No.1225 I hate I hate Matrix Construction
ユーザー rutilicus
提出日時 2020-09-12 12:04:04
言語 Kotlin
(2.1.0)
結果
AC  
実行時間 322 ms / 2,000 ms
コード長 848 bytes
コンパイル時間 15,400 ms
コンパイル使用メモリ 433,788 KB
実行使用メモリ 57,032 KB
最終ジャッジ日時 2024-12-31 14:36:17
合計ジャッジ時間 27,228 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:41:13: warning: 'appendln(Int): kotlin.text.StringBuilder /* = java.lang.StringBuilder */' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
    builder.appendln(ans)
            ^

ソースコード

diff #

import kotlin.math.max

fun main() {
    val builder = StringBuilder()

    // なにもわからん
    val n = readInputLine().toInt()

    val s = readInputLine()
    val t = readInputLine()

    var s1Cnt = 0
    var s2Cnt = 0
    var t1Cnt = 0
    var t2Cnt = 0

    for (c in s) {
        when (c) {
            '1' -> s1Cnt++
            '2' -> s2Cnt++
        }
    }

    for (c in t) {
        when (c) {
            '1' -> t1Cnt++
            '2' -> t2Cnt++
        }
    }

    var ans = if (s2Cnt != 0 && t2Cnt != 0) {
        n * (s2Cnt + t2Cnt) - s2Cnt * t2Cnt
    } else if (t2Cnt != 0) {
        n * t2Cnt + t1Cnt
    } else if (s2Cnt != 0) {
        n * s2Cnt + s1Cnt
    } else {
        max(s1Cnt, t1Cnt)
    }

    builder.appendln(ans)

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}
0