Submission #62813723
Source Code Expand
import kotlin.math.abs
import kotlin.math.min
import kotlin.collections.mutableListOf
fun getAbsSum(idxs: MutableList<Long>, medianIdx: Int): Long {
val median = idxs[medianIdx]
var sum = 0L
for (v in idxs) {
sum += abs(v - median)
}
return sum;
}
fun main() {
readln()
val S = readln()
val idxs = mutableListOf<Long>()
var ofs = 0
for (i in 0..S.length-1) {
if (S[i] == '1') {
idxs.add((i - ofs).toLong())
ofs++
}
}
// median of idxs
var sum: Long
if (idxs.size % 2 == 0) {
val sum1 = getAbsSum(idxs, (idxs.size - 1) / 2)
val sum2 = getAbsSum(idxs, (idxs.size - 1) / 2 + 1)
sum = min(sum1, sum2)
} else {
sum = getAbsSum(idxs, (idxs.size - 1) / 2)
}
println(sum)
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Swap to Gather |
| User | bugtori |
| Language | Kotlin (Kotlin/JVM 1.8.20) |
| Score | 425 |
| Code Size | 849 Byte |
| Status | AC |
| Exec Time | 195 ms |
| Memory | 67392 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 425 / 425 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 44 ms | 37400 KiB |
| 00_sample_01.txt | AC | 42 ms | 37484 KiB |
| 00_sample_02.txt | AC | 48 ms | 37420 KiB |
| 01_random_00.txt | AC | 106 ms | 40684 KiB |
| 01_random_01.txt | AC | 169 ms | 50864 KiB |
| 01_random_02.txt | AC | 156 ms | 49652 KiB |
| 01_random_03.txt | AC | 129 ms | 42320 KiB |
| 01_random_04.txt | AC | 142 ms | 45040 KiB |
| 01_random_05.txt | AC | 168 ms | 46336 KiB |
| 01_random_06.txt | AC | 174 ms | 48020 KiB |
| 01_random_07.txt | AC | 159 ms | 50040 KiB |
| 01_random_08.txt | AC | 161 ms | 52764 KiB |
| 01_random_09.txt | AC | 182 ms | 54040 KiB |
| 01_random_10.txt | AC | 182 ms | 55480 KiB |
| 01_random_11.txt | AC | 171 ms | 67188 KiB |
| 01_random_12.txt | AC | 195 ms | 67392 KiB |
| 01_random_13.txt | AC | 155 ms | 49008 KiB |
| 02_random2_00.txt | AC | 168 ms | 45548 KiB |
| 02_random2_01.txt | AC | 164 ms | 54468 KiB |
| 02_random2_02.txt | AC | 170 ms | 43616 KiB |
| 02_random2_03.txt | AC | 152 ms | 43460 KiB |
| 02_random2_04.txt | AC | 169 ms | 46320 KiB |
| 02_random2_05.txt | AC | 164 ms | 50196 KiB |
| 03_handmade_00.txt | AC | 48 ms | 37560 KiB |
| 03_handmade_01.txt | AC | 42 ms | 37492 KiB |
| 03_handmade_02.txt | AC | 47 ms | 37576 KiB |
| 03_handmade_03.txt | AC | 42 ms | 37468 KiB |
| 03_handmade_04.txt | AC | 159 ms | 49752 KiB |