結果

問題 No.1438 Broken Drawers
ユーザー 炭酸水炭酸水
提出日時 2022-05-14 05:40:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 1,415 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 30,796 KB
最終ジャッジ日時 2023-09-29 17:58:48
合計ジャッジ時間 5,542 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,072 KB
testcase_01 AC 14 ms
8,108 KB
testcase_02 AC 14 ms
8,200 KB
testcase_03 AC 14 ms
8,136 KB
testcase_04 AC 15 ms
8,100 KB
testcase_05 AC 16 ms
8,076 KB
testcase_06 AC 164 ms
30,104 KB
testcase_07 AC 199 ms
30,080 KB
testcase_08 AC 15 ms
8,040 KB
testcase_09 AC 15 ms
8,076 KB
testcase_10 AC 15 ms
8,136 KB
testcase_11 AC 25 ms
9,252 KB
testcase_12 AC 99 ms
16,484 KB
testcase_13 AC 151 ms
22,120 KB
testcase_14 AC 73 ms
14,180 KB
testcase_15 AC 225 ms
29,508 KB
testcase_16 AC 218 ms
27,896 KB
testcase_17 AC 227 ms
30,108 KB
testcase_18 AC 234 ms
30,296 KB
testcase_19 AC 235 ms
30,468 KB
testcase_20 AC 237 ms
30,740 KB
testcase_21 AC 236 ms
30,288 KB
testcase_22 AC 237 ms
30,796 KB
testcase_23 AC 240 ms
30,052 KB
testcase_24 AC 243 ms
30,036 KB
testcase_25 AC 237 ms
30,116 KB
testcase_26 AC 244 ms
30,084 KB
testcase_27 AC 239 ms
30,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))

if n == 1:
    print(1)

elif n == 2:
    if a[0] < a[1]:
        print(2)
    else:
        print(1)

else:
    z = []

    if a[0] < a[1]:
        z.append(True)
    elif a[0] > a[1]:
        if a[1] < a[2]:
            z.append(False)
        elif a[1] > a[2]:
            z.append(True)
    
    for i in range(1, n - 1):
        if a[i - 1] < a[i] < a[i + 1]:
            z.append(True)
        
        elif a[i - 1] > a[i] > a[i + 1]:
            if z[i - 1]:
                z.append(False)
            else:
                z.append(True)
        
        elif a[i - 1] > a[i] < a[i + 1]:
            if z[i - 1]:
                z.append(False)
            else:
                z.append(True)
        
        elif a[i - 1] < a[i] > a[i + 1]:
            if z[i - 1]:
                z.append(True)
            else:
                if i < n - 2:
                    if a[i + 1] < a[i + 2]:
                        z.append(False)
                    elif a[i + 1] > a[i + 2]:
                        z.append(True)
                elif i == n - 2:
                    z.append(True)
    
    if a[-2] < a[-1]:
        z.append(True)
    elif a[-2] > a[-1]:
        if z[-1]:
            z.append(False)
        else:
            z.append(True)
    
    ans = 0        
    for i in range(n):
        if z[i]:
            ans += 1
    
    print(ans)
0