結果

問題 No.116 門松列(1)
ユーザー yo-kondoyo-kondo
提出日時 2018-03-25 21:07:09
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 324 ms / 5,000 ms
コード長 991 bytes
コンパイル時間 12,505 ms
コンパイル使用メモリ 440,396 KB
実行使用メモリ 57,008 KB
最終ジャッジ日時 2024-04-30 17:35:34
合計ジャッジ時間 20,590 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 314 ms
56,860 KB
testcase_01 AC 308 ms
56,844 KB
testcase_02 AC 318 ms
56,800 KB
testcase_03 AC 314 ms
56,820 KB
testcase_04 AC 314 ms
56,860 KB
testcase_05 AC 317 ms
56,884 KB
testcase_06 AC 311 ms
56,908 KB
testcase_07 AC 314 ms
56,804 KB
testcase_08 AC 313 ms
56,812 KB
testcase_09 AC 316 ms
56,944 KB
testcase_10 AC 311 ms
56,828 KB
testcase_11 AC 319 ms
56,916 KB
testcase_12 AC 315 ms
56,844 KB
testcase_13 AC 313 ms
56,836 KB
testcase_14 AC 324 ms
57,000 KB
testcase_15 AC 316 ms
56,836 KB
testcase_16 AC 322 ms
56,856 KB
testcase_17 AC 316 ms
56,836 KB
testcase_18 AC 316 ms
56,872 KB
testcase_19 AC 317 ms
56,964 KB
testcase_20 AC 318 ms
56,824 KB
testcase_21 AC 321 ms
56,880 KB
testcase_22 AC 318 ms
56,936 KB
testcase_23 AC 323 ms
57,008 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:6:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

package yukicoder.no116

/**
 * エントリポイント
 */
fun main(args: Array<String>) {
    val in1 = readLine()
    val in2 = readLine()
    print(pineDecoration(in1, in2))
}

/**
 * 門松列になっている数を返します。
 * @param bambooNum 竹の数
 * @param bambooHeights それぞれの竹の長さ
 */
fun pineDecoration(@Suppress("UNUSED_PARAMETER") bambooNum: String?,
                   bambooHeights: String?): String {
    if (bambooHeights == null) {
        return ""
    }

    var count = 0
    val sp = bambooHeights.split(" ").map { it.toInt() }
    for (i in 1..(sp.size - 2)) {
        // すべて違う高さ
        if (sp[i - 1] == sp[i] || sp[i - 1] == sp[i + 1] || sp[i] == sp[i + 1]) {
            continue
        }
        // 中央が2番目の高さではない
        if ((sp[i - 1] > sp[i] && sp[i] > sp[i + 1]) || (sp[i - 1] < sp[i] && sp[i] < sp[i + 1])) {
            continue
        }
        count++
    }
    return count.toString()
}
0