Submission #6782221


Source Code Expand

Copy
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) = IO().exec {
    val s = string()
    val key = "keyence"
    var state = 0
    var j = 0
    for (i in 0 until s.length) {
        if (s[i] != key[j]) {
            if (i == 0 || (i >= 1 && j >= 1 && s[i-1] == key[j-1])) state++
        } else {
            j++
            if (j == key.length) {
                if (i != s.length-1) state++
                break
            }
        }
    }
    println(if (j == key.length && state <= 1) "YES" else "NO")
}

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }
    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun string(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun long(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}

Submission Info

Submission Time
Task B - KEYENCE String
User henoc
Language Kotlin (1.0.0)
Score 0
Code Size 2660 Byte
Status
Exec Time 174 ms
Memory 31384 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt, s4.txt
All 0 / 200 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt 171 ms 27552 KB
02.txt 170 ms 29344 KB
03.txt 169 ms 29344 KB
04.txt 165 ms 29352 KB
05.txt 169 ms 25620 KB
06.txt 169 ms 27412 KB
07.txt 165 ms 29356 KB
08.txt 166 ms 31384 KB
09.txt 170 ms 29472 KB
10.txt 167 ms 27292 KB
11.txt 169 ms 27540 KB
12.txt 169 ms 29472 KB
13.txt 166 ms 27428 KB
14.txt 168 ms 29340 KB
s1.txt 169 ms 29328 KB
s2.txt 174 ms 29344 KB
s3.txt 164 ms 31128 KB
s4.txt 167 ms 29340 KB