結果

問題 No.2073 Concon Substrings (Swap Version)
ユーザー 👑 箱
提出日時 2022-09-16 22:31:27
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 570 ms / 2,000 ms
コード長 1,697 bytes
コンパイル時間 17,323 ms
コンパイル使用メモリ 431,268 KB
実行使用メモリ 62,504 KB
最終ジャッジ日時 2023-08-23 16:07:41
合計ジャッジ時間 39,047 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 283 ms
53,192 KB
testcase_01 AC 280 ms
52,956 KB
testcase_02 AC 281 ms
55,044 KB
testcase_03 AC 283 ms
53,176 KB
testcase_04 AC 280 ms
53,172 KB
testcase_05 AC 556 ms
60,232 KB
testcase_06 AC 556 ms
62,236 KB
testcase_07 AC 280 ms
54,924 KB
testcase_08 AC 519 ms
60,084 KB
testcase_09 AC 522 ms
58,268 KB
testcase_10 AC 563 ms
60,476 KB
testcase_11 AC 570 ms
60,736 KB
testcase_12 AC 283 ms
54,860 KB
testcase_13 AC 357 ms
56,568 KB
testcase_14 AC 549 ms
58,076 KB
testcase_15 AC 489 ms
58,196 KB
testcase_16 AC 540 ms
62,504 KB
testcase_17 AC 276 ms
53,068 KB
testcase_18 AC 348 ms
54,572 KB
testcase_19 AC 539 ms
60,404 KB
testcase_20 AC 531 ms
60,152 KB
testcase_21 AC 526 ms
58,460 KB
testcase_22 AC 545 ms
60,912 KB
testcase_23 AC 277 ms
54,964 KB
testcase_24 AC 291 ms
53,228 KB
testcase_25 AC 516 ms
59,976 KB
testcase_26 AC 563 ms
62,336 KB
testcase_27 AC 292 ms
53,380 KB
testcase_28 AC 562 ms
58,472 KB
testcase_29 AC 507 ms
60,532 KB
testcase_30 AC 544 ms
59,952 KB
testcase_31 AC 523 ms
60,372 KB
testcase_32 AC 400 ms
58,920 KB
testcase_33 AC 472 ms
60,084 KB
testcase_34 AC 405 ms
58,672 KB
testcase_35 AC 521 ms
60,152 KB
testcase_36 AC 461 ms
58,136 KB
testcase_37 AC 531 ms
58,352 KB
testcase_38 AC 406 ms
57,168 KB
testcase_39 AC 532 ms
58,104 KB
testcase_40 AC 515 ms
58,180 KB
testcase_41 AC 534 ms
58,312 KB
権限があれば一括ダウンロードができます

ソースコード

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