提出 #5226237
ソースコード 拡げる
import scala.collection.mutable.ArrayBuffer
object Scanner {
private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
@inline private def hasNextByte(): Boolean =
if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
@inline private def hasNext(): Boolean = {
while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
hasNextByte()
}
@inline private def readByte(): Byte =
if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
def next(): String = {
if(!hasNext()) ???
val sb = new StringBuilder; var b = readByte()
while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
sb.toString
}
def nextInt(): Int = {
val n = nextLong()
if (n < Int.MinValue || Int.MaxValue < n) ???
n.toInt
}
def nextLong(): Long = {
if(!hasNext()) ???
var minus = false; var b = readByte()
if (b == '-') { minus = true; b = readByte() }
def go (b: Byte, n: Long = 0): Long =
if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
else if (minus) { -n } else { n }
go(b)
}
def nextDouble(): Double = next.toDouble
}
object Main extends App {
val n = Scanner.nextInt
val k = Scanner.nextInt
val s = Scanner.next
val sArray = s.toCharArray
var turningPoints = new ArrayBuffer[Int]
sArray.zipWithIndex.foreach(a=>{
if (a._2 == 0) {
turningPoints += a._2
} else {
if (a._1 != sArray(a._2-1)){
turningPoints += a._2
}
}
})
val result = turningPoints.zipWithIndex.map(t=>{
if (sArray(t._1) == '0') {
if ((t._2+2*k)>=turningPoints.length){
n-t._1
} else {
turningPoints(t._2+2*k)-t._1
}
} else{
if ((t._2+2*k+1)>=turningPoints.length){
n-t._1
} else {
turningPoints(t._2+2*k+1)-t._1
}
}
}).max
println(result)
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Handstand |
| ユーザ | nanananakam |
| 言語 | Scala (2.11.7) |
| 得点 | 400 |
| コード長 | 2057 Byte |
| 結果 | AC |
| 実行時間 | 630 ms |
| メモリ | 41348 KiB |
ジャッジ結果
| セット名 | All | Sample | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 400 / 400 | 0 / 0 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| All | sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15 |
| Sample | sample_01, sample_02, sample_03 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| sample_01 | AC | 326 ms | 25288 KiB |
| sample_02 | AC | 323 ms | 25284 KiB |
| sample_03 | AC | 327 ms | 25400 KiB |
| testcase_01 | AC | 450 ms | 28760 KiB |
| testcase_02 | AC | 442 ms | 28384 KiB |
| testcase_03 | AC | 537 ms | 36456 KiB |
| testcase_04 | AC | 323 ms | 24900 KiB |
| testcase_05 | AC | 559 ms | 41348 KiB |
| testcase_06 | AC | 590 ms | 40680 KiB |
| testcase_07 | AC | 623 ms | 39432 KiB |
| testcase_08 | AC | 606 ms | 41084 KiB |
| testcase_09 | AC | 630 ms | 41080 KiB |
| testcase_10 | AC | 423 ms | 31780 KiB |
| testcase_11 | AC | 435 ms | 28208 KiB |
| testcase_12 | AC | 440 ms | 30308 KiB |
| testcase_13 | AC | 427 ms | 32196 KiB |
| testcase_14 | AC | 427 ms | 32156 KiB |
| testcase_15 | AC | 322 ms | 25260 KiB |