Submission #54814100


Source Code Expand

import MutableIntMap.Companion.mutableIntMapOf
import java.io.*
import java.util.*
import kotlin.collections.*
import kotlin.math.*

val INPUT: InputStream = System.`in`
val OUTPUT: PrintStream = System.out

val _reader = INPUT.bufferedReader()

var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
    while (!_tokenizer.hasMoreTokens()) {
        _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ")
    }
    return _tokenizer.nextToken()
}

fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readInts(n: Int) = List(n) { readInt() }
fun readIntArray(n: Int) = IntArray(n) { readInt() }
fun readDoubles(n: Int) = List(n) { readDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }
fun readLongs(n: Int) = List(n) { readLong() }
fun readLongArray(n: Int) = LongArray(n) { readLong() }

val _writer = PrintWriter(OUTPUT, false)
inline fun output(block: PrintWriter.() -> Unit) {
    _writer.apply(block).flush()
}

class MutableIntMap<K> : LinkedHashMap<K, Int>() {
    override operator fun get(key: K): Int = super.get(key) ?: 0

    fun increment(key: K, value: Int = 1) {
        this[key] = this[key] + value
    }

    companion object {
        fun <K> mutableIntMapOf(vararg pairs: Pair<K, Int>) =
            MutableIntMap<K>().apply { putAll(pairs) }
    }
}

typealias Pii = Pair<Int, Int>

fun readPii() = readInt() to readInt()
fun readPiis(n: Int) = List(n) { readPii() }

infix fun Int.hasBit(i: Int): Boolean = this and (1 shl i) > 0
infix fun Int.xorBit(i: Int): Int = this xor (1 shl i)
infix fun Long.hasBit(i: Int): Boolean = this and (1L shl i) > 0
infix fun Long.xorBit(i: Int): Long = this xor (1L shl i)

fun largerStackSize(stackSizeMegaBytes: Int = 100, action: () -> Unit) {
    Thread(null, action, "", 1024L * 1024 * stackSizeMegaBytes).apply {
        start()
        join()
    }
}

// #################################################################################################

fun solve() {
    val sx = readLong()
    val sy = readLong()
    val tx = readLong()
    val ty = readLong()
    val y = (sy - ty).absoluteValue
    val x = (sx - tx).absoluteValue
    var t = if (sx > tx) {
        (sx + sy) % 2
    } else {
        (sx + sy + 1) % 2
    }
    t += y
    println(y + ((x - t).coerceAtLeast(0) + 1) / 2)
}

fun main() {
//    repeat(readInt()) { solve() }
    solve()
}

Submission Info

Submission Time
Task C - Tile Distance 2
User wangchaohui
Language Kotlin (Kotlin/JVM 1.8.20)
Score 350
Code Size 2563 Byte
Status AC
Exec Time 51 ms
Memory 38320 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 49
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_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, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 46 ms 38092 KiB
00_sample_01.txt AC 49 ms 37892 KiB
00_sample_02.txt AC 51 ms 38088 KiB
01_random_03.txt AC 46 ms 38016 KiB
01_random_04.txt AC 47 ms 38056 KiB
01_random_05.txt AC 49 ms 38212 KiB
01_random_06.txt AC 51 ms 38136 KiB
01_random_07.txt AC 45 ms 38104 KiB
01_random_08.txt AC 48 ms 38056 KiB
01_random_09.txt AC 47 ms 38108 KiB
01_random_10.txt AC 50 ms 38176 KiB
01_random_11.txt AC 51 ms 38320 KiB
01_random_12.txt AC 50 ms 38136 KiB
01_random_13.txt AC 49 ms 38020 KiB
01_random_14.txt AC 48 ms 38224 KiB
01_random_15.txt AC 49 ms 38048 KiB
01_random_16.txt AC 46 ms 38012 KiB
01_random_17.txt AC 46 ms 38072 KiB
01_random_18.txt AC 47 ms 38036 KiB
01_random_19.txt AC 47 ms 37936 KiB
01_random_20.txt AC 49 ms 38020 KiB
01_random_21.txt AC 51 ms 38236 KiB
01_random_22.txt AC 47 ms 37976 KiB
01_random_23.txt AC 49 ms 38004 KiB
01_random_24.txt AC 47 ms 38224 KiB
01_random_25.txt AC 46 ms 38056 KiB
01_random_26.txt AC 49 ms 38192 KiB
01_random_27.txt AC 50 ms 38164 KiB
01_random_28.txt AC 48 ms 38008 KiB
01_random_29.txt AC 50 ms 38224 KiB
01_random_30.txt AC 46 ms 37936 KiB
01_random_31.txt AC 51 ms 38136 KiB
01_random_32.txt AC 49 ms 38212 KiB
01_random_33.txt AC 50 ms 38320 KiB
01_random_34.txt AC 46 ms 38112 KiB
01_random_35.txt AC 47 ms 37956 KiB
01_random_36.txt AC 51 ms 38204 KiB
01_random_37.txt AC 50 ms 38216 KiB
01_random_38.txt AC 46 ms 37964 KiB
01_random_39.txt AC 46 ms 38112 KiB
01_random_40.txt AC 47 ms 38032 KiB
01_random_41.txt AC 51 ms 38236 KiB
01_random_42.txt AC 45 ms 38168 KiB
01_random_43.txt AC 50 ms 38148 KiB
01_random_44.txt AC 50 ms 38160 KiB
01_random_45.txt AC 46 ms 37900 KiB
01_random_46.txt AC 46 ms 38104 KiB
01_random_47.txt AC 50 ms 38048 KiB
01_random_48.txt AC 50 ms 38256 KiB