結果

問題 No.2073 Concon Substrings (Swap Version)
ユーザー koboshikoboshi
提出日時 2022-09-16 22:31:27
言語 Kotlin
(1.6.10)
結果
AC  
実行時間 502 ms / 2,000 ms
コード長 1,697 bytes
コンパイル時間 13,147 ms
使用メモリ 59,716 KB
最終ジャッジ日時 2023-01-11 07:45:19
合計ジャッジ時間 31,729 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 227 ms
46,188 KB
testcase_01 AC 228 ms
45,968 KB
testcase_02 AC 225 ms
46,088 KB
testcase_03 AC 234 ms
46,328 KB
testcase_04 AC 224 ms
48,044 KB
testcase_05 AC 469 ms
58,932 KB
testcase_06 AC 502 ms
58,284 KB
testcase_07 AC 231 ms
46,124 KB
testcase_08 AC 452 ms
59,084 KB
testcase_09 AC 470 ms
56,976 KB
testcase_10 AC 476 ms
59,716 KB
testcase_11 AC 490 ms
59,424 KB
testcase_12 AC 229 ms
46,136 KB
testcase_13 AC 304 ms
51,312 KB
testcase_14 AC 491 ms
57,676 KB
testcase_15 AC 416 ms
57,848 KB
testcase_16 AC 493 ms
57,484 KB
testcase_17 AC 228 ms
46,052 KB
testcase_18 AC 304 ms
51,228 KB
testcase_19 AC 484 ms
55,232 KB
testcase_20 AC 500 ms
57,224 KB
testcase_21 AC 499 ms
59,228 KB
testcase_22 AC 495 ms
57,840 KB
testcase_23 AC 228 ms
46,184 KB
testcase_24 AC 243 ms
48,168 KB
testcase_25 AC 495 ms
59,160 KB
testcase_26 AC 485 ms
57,372 KB
testcase_27 AC 226 ms
45,980 KB
testcase_28 AC 502 ms
57,216 KB
testcase_29 AC 446 ms
57,828 KB
testcase_30 AC 448 ms
57,920 KB
testcase_31 AC 450 ms
58,164 KB
testcase_32 AC 331 ms
51,512 KB
testcase_33 AC 392 ms
53,688 KB
testcase_34 AC 348 ms
51,664 KB
testcase_35 AC 432 ms
58,060 KB
testcase_36 AC 370 ms
53,436 KB
testcase_37 AC 416 ms
58,020 KB
testcase_38 AC 362 ms
51,504 KB
testcase_39 AC 468 ms
58,144 KB
testcase_40 AC 469 ms
58,268 KB
testcase_41 AC 453 ms
58,088 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