結果
問題 | No.2073 Concon Substrings (Swap Version) |
ユーザー | 箱星 |
提出日時 | 2022-09-16 22:09:04 |
言語 | Kotlin (1.9.23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,485 bytes |
コンパイル時間 | 14,891 ms |
コンパイル使用メモリ | 454,748 KB |
実行使用メモリ | 72,212 KB |
最終ジャッジ日時 | 2024-06-01 13:10:27 |
合計ジャッジ時間 | 37,644 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 323 ms
59,148 KB |
testcase_01 | AC | 315 ms
59,076 KB |
testcase_02 | AC | 321 ms
59,136 KB |
testcase_03 | AC | 315 ms
59,244 KB |
testcase_04 | AC | 314 ms
59,104 KB |
testcase_05 | AC | 582 ms
71,936 KB |
testcase_06 | AC | 587 ms
71,900 KB |
testcase_07 | AC | 318 ms
59,100 KB |
testcase_08 | AC | 577 ms
67,868 KB |
testcase_09 | AC | 601 ms
67,812 KB |
testcase_10 | AC | 598 ms
72,128 KB |
testcase_11 | AC | 588 ms
72,136 KB |
testcase_12 | AC | 318 ms
59,188 KB |
testcase_13 | AC | 392 ms
60,544 KB |
testcase_14 | AC | 590 ms
71,912 KB |
testcase_15 | AC | 566 ms
63,932 KB |
testcase_16 | AC | 572 ms
72,084 KB |
testcase_17 | AC | 319 ms
59,120 KB |
testcase_18 | AC | 383 ms
60,624 KB |
testcase_19 | AC | 578 ms
72,028 KB |
testcase_20 | AC | 570 ms
67,968 KB |
testcase_21 | AC | 565 ms
67,960 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 609 ms
67,828 KB |
testcase_31 | AC | 540 ms
63,748 KB |
testcase_32 | AC | 412 ms
62,876 KB |
testcase_33 | AC | 479 ms
63,728 KB |
testcase_34 | AC | 415 ms
62,888 KB |
testcase_35 | AC | 596 ms
66,000 KB |
testcase_36 | AC | 483 ms
63,464 KB |
testcase_37 | AC | 573 ms
65,680 KB |
testcase_38 | AC | 426 ms
62,856 KB |
testcase_39 | AC | 633 ms
68,132 KB |
testcase_40 | AC | 564 ms
65,692 KB |
testcase_41 | AC | 609 ms
68,028 KB |
ソースコード
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 (con0 > 0 && con1 > 0 && con2 > 0 && x0 == 0 && x1 == 0 && x2 == 0 && con == n) { println(con - 1) } else { println(con) } } class UnionFind(n: Int) { private val rank = IntArray(n) { 0 } private val parent = IntArray(n) { -1 } fun find(x: Int): Int { if (parent[x] < 0) { return x } parent[x] = find(parent[x]) return parent[x] } fun unite(x: Int, y: Int) { val x1 = find(x) val y1 = find(y) if (x1 == y1) { return } if (rank[x1] < rank[y1]) { parent[y1] += parent[x1] parent[x1] = y1 } else { parent[x1] += parent[y1] parent[y1] = x1 if (rank[x1] == rank[y1]) { rank[x1]++ } } } fun same(x: Int, y: Int): Boolean { return find(x) == find(y) } fun size(x: Int): Int { return -parent[find(x)] } } 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