結果

問題 No.2073 Concon Substrings (Swap Version)
ユーザー 箱星
提出日時 2022-09-16 22:31:27
言語 Kotlin
(2.1.0)
結果
AC  
実行時間 610 ms / 2,000 ms
コード長 1,697 bytes
コンパイル時間 15,372 ms
コンパイル使用メモリ 442,760 KB
実行使用メモリ 65,356 KB
最終ジャッジ日時 2024-12-21 21:47:08
合計ジャッジ時間 37,420 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fun PrintWriter.solve() {
    val n = nextInt()
    val s = nextLine()
    val s0 = (0 until n).map { s[3 * it] }
    val s1 = (0 until n).map { s[3 * it + 1] }
    val s2 = (0 until n).map { s[3 * it + 2] }
    val c0 = s0.count { it == 'c' }
    val c1 = s1.count { it == 'c' }
    val c2 = s2.count { it == 'c' }
    val o0 = s0.count { it == 'o' }
    val o1 = s1.count { it == 'o' }
    val o2 = s2.count { it == 'o' }
    val n0 = s0.count { it == 'n' }
    val n1 = s1.count { it == 'n' }
    val n2 = s2.count { it == 'n' }
    val x0 = n - c0 - o0 - n0
    val x1 = n - c1 - o1 - n1
    val x2 = n - c2 - o2 - n2
    val con0 = minOf(c0, o1, n2)
    val con1 = minOf(c1, o2, n0)
    val con2 = minOf(c2, o0, n1)
    val con = con0 + con1 + con2
    if (x0 == 0 && x1 == 0 && x2 == 0 && con == n) {
        if (con0 == n) {
            println(con)
        } else {
            println(con - 1)
        }
    } else {
        println(con)
    }
}

fun main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", abs(1L.shl(26)))
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()
}

// 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