結果

問題 No.1438 Broken Drawers
ユーザー 炭酸水
提出日時 2022-05-14 05:40:34
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 1,415 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 30,284 KB
最終ジャッジ日時 2024-07-22 11:57:21
合計ジャッジ時間 5,877 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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