結果

問題 No.1765 While Shining
ユーザー 👑 箱
提出日時 2021-10-21 21:27:20
言語 Kotlin
(1.9.10)
結果
AC  
実行時間 451 ms / 2,000 ms
コード長 1,334 bytes
コンパイル時間 15,317 ms
コンパイル使用メモリ 422,652 KB
実行使用メモリ 60,204 KB
最終ジャッジ日時 2023-09-12 04:45:57
合計ジャッジ時間 25,099 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 276 ms
52,600 KB
testcase_01 AC 277 ms
54,324 KB
testcase_02 AC 278 ms
52,840 KB
testcase_03 AC 276 ms
52,576 KB
testcase_04 AC 282 ms
54,216 KB
testcase_05 AC 286 ms
52,620 KB
testcase_06 AC 284 ms
54,348 KB
testcase_07 AC 284 ms
54,364 KB
testcase_08 AC 283 ms
52,640 KB
testcase_09 AC 421 ms
59,692 KB
testcase_10 AC 446 ms
60,048 KB
testcase_11 AC 437 ms
57,848 KB
testcase_12 AC 439 ms
59,860 KB
testcase_13 AC 439 ms
56,212 KB
testcase_14 AC 443 ms
59,912 KB
testcase_15 AC 447 ms
60,200 KB
testcase_16 AC 451 ms
58,352 KB
testcase_17 AC 450 ms
57,976 KB
testcase_18 AC 432 ms
59,896 KB
testcase_19 AC 436 ms
57,968 KB
testcase_20 AC 444 ms
60,204 KB
testcase_21 AC 438 ms
57,860 KB
testcase_22 AC 436 ms
57,916 KB
testcase_23 AC 437 ms
59,988 KB
testcase_24 AC 430 ms
59,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextInt()
    val a = IntArray(n) { nextInt() }
    val b = IntArray(n) { i -> if (i % 2 == 0) a[i] else 1 - a[i] }
    val c = IntArray(n) { 0 }
    var streak = 1
    var prev = -1
    for (i in n - 1 downTo 0) {
        if (i == n - 1) {
            streak = 0
            prev = b[i]
        } else if (b[i] != prev) {
            prev = b[i]
            streak = 1
        } else {
            streak++
        }
        c[i] = streak
    }
    var ans = 0L
    for (i in 0 until n - 1) {
        if (a[i] == 1) ans += c[i]
    }
    println(ans)
}

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
0