結果

問題 No.116 門松列(1)
ユーザー minokasagominokasago
提出日時 2019-11-01 16:03:09
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 312 ms / 5,000 ms
コード長 615 bytes
コンパイル時間 15,216 ms
コンパイル使用メモリ 415,512 KB
実行使用メモリ 49,600 KB
最終ジャッジ日時 2023-10-13 00:50:48
合計ジャッジ時間 24,406 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 300 ms
49,308 KB
testcase_01 AC 300 ms
49,500 KB
testcase_02 AC 299 ms
49,180 KB
testcase_03 AC 298 ms
49,500 KB
testcase_04 AC 301 ms
49,592 KB
testcase_05 AC 301 ms
49,132 KB
testcase_06 AC 301 ms
49,256 KB
testcase_07 AC 300 ms
49,424 KB
testcase_08 AC 295 ms
49,596 KB
testcase_09 AC 295 ms
49,144 KB
testcase_10 AC 301 ms
49,336 KB
testcase_11 AC 302 ms
49,600 KB
testcase_12 AC 297 ms
49,188 KB
testcase_13 AC 303 ms
49,536 KB
testcase_14 AC 300 ms
49,548 KB
testcase_15 AC 293 ms
49,244 KB
testcase_16 AC 305 ms
49,156 KB
testcase_17 AC 301 ms
49,600 KB
testcase_18 AC 302 ms
49,300 KB
testcase_19 AC 302 ms
49,468 KB
testcase_20 AC 301 ms
49,552 KB
testcase_21 AC 307 ms
49,292 KB
testcase_22 AC 304 ms
49,104 KB
testcase_23 AC 312 ms
49,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import kotlin.math.*

fun main()
{
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map(String::toInt)

    var ans = 0
    for (i in 0..N-3) {
        if (isDistinct(A[i], A[i+1], A[i+2]) && A[i+1] != med(A[i], A[i+1], A[i+2])) {
            ans++;
        }
    }
    
    println(ans)
}

fun isDistinct(a: Int, b:Int, c:Int): Boolean {
    return a != b && b != c && c != a
}

fun med(a: Int, b: Int, c: Int): Int {
    if (a <= b) {
        if (c <= a) return a
        if (c <= b) return c
    } else {
        if (a <= c) return a
        if (b <= c) return c        
    }
    return b
}
0