Problem:


Score : 300 points

Problem Statement

You are given an array A of length N.
Your task is to divide it into several contiguous subarrays.
Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order.
At least how many subarrays do you need to divide A into?

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Each A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible number of subarrays after division of A.

Sample Input 1

6
1 2 3 2 2 1

Sample Output 1

2

One optimal solution is to divide the array into [1,2,3] and [2,2,1].

Sample Input 2

9
1 2 1 2 1 2 1 2 1

Sample Output 2

5

Sample Input 3

7
1 2 3 2 1 999999999 1000000000

Sample Output 3

3



Sample input:
6
1 2 3 2 2 1


Sample output:
2

Submission status: Wrong Answer

Solution code:
N = input()
As = [int(x) for x in input().split()]

idx = 0
mode_change_count = 1
while True:
    if idx >= (len(As)-2):
        break
    if (As[idx+1] - As[idx])*(As[idx+2] - As[idx+1]) >= 0:
        idx += 1
        continue
    elif (As[idx+1] - As[idx])*(As[idx+2] - As[idx+1]) < 0:
        idx += 2
        mode_change_count += 1
        continue

print(mode_change_count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.append(a[-1])
f = 0
ans = 1
for i in range(n-1):
    if a[i] == a[i+1]:
        pass
    elif f == 0:
        if a[i] < a[i+1]:
            pass
        else:
            ans += 1
            if a[i+1] < a[i+2]:
                f = 0
            else:
                f = 1
    else:
        if a[i] > a[i+1]:
            pass
        else:
            ans += 1
            if a[i+1] < a[i+2]:
                f = 0
            else:
                f = 1

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
diff=[a[i+1]-a[i] for i in range(N-1)]
ans=[0,0]

for i in range(N-1):
  if diff[i]<0:
    ans[0]+=1
  elif diff[i]>0:
    ans[1]+=1
print(min(ans)+1)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
diff=[a[i+1]-a[i] for i in range(N-1)]
ans=1
for i in range(N-2):
  if diff[i]*diff[i+1]<0:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
# A - Sorted Arrays
N = int(input())
A = list(map(int,input().split()))

# 1:plus -1:minus
plus_minus = 0
ans = 0
for i in range(N-1):

    if A[i+1]-A[i]>0:
        if plus_minus == 0:
            ans += 1
            plus_minus = 1
        elif plus_minus == -1:
            # ans += 1
            plus_minus = 0
        
    elif A[i+1]-A[i]<0:
        if plus_minus == 0:
            ans += 1
            plus_minus = -1
        elif plus_minus == 1:
            # ans += 1
            plus_minus = 0
    
    if i+1==N-1:
        if plus_minus == 0:
            ans += 1
            continue

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
b = [0] * (n-1)
for i in range(n-1):
    if a[i] < a[i+1]:
        b[i] = 0
    elif a[i] > a[i+1]:
        b[i] = 1
    else:
        b[i] = 2
res = 0
i = 0
while i < n-2:
    if (b[i] == 0 and b[i+1] == 1) or (b[i] == 1 and b[i+1] == 0):
        res += 1
        i += 1
    i += 1
print(res+1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
_=int(input())
A=list(map(int,input().split()))
N=len(A)

trend=0
ans=0
for i in range(N-1):
    temp=A[i+1]-A[i]
    if trend==0:
        if temp>0:
            trend=1
            ans+=1
        elif temp<0:
            trend=-1
            ans+=1
        else:
            pass
    elif trend==1:
        if temp>0:
            pass
        elif temp<0:
            trend=0
        else:
            pass
    elif trend==-1:
        if temp>0:
            trend=0
        elif temp<0:
            pass
        else:
            pass
print(trend)
print(ans if trend!=0 else ans+1)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))

if N==1:
    print(1)
    exit()

ans=0
pre=A[1]-A[0]
cool=True
for_last=False
for i in range(N-2):
    temp=A[i+2]-A[i+1]
    if temp==0:
        cool=True
        for_last=True
        continue
    elif pre*temp<0 and cool:
        ans+=1
        if i==N-3 and for_last:
            ans-=1
        cool=False
        for_last=False
    else:
        cool=True
        for_last=False
    pre=temp
    
#print(for_last)
print(ans+1)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))

if N==1:
    print(1)
    exit()

ans=0
pre=A[1]-A[0]
cool=True
for_last=False
for i in range(N-2):
    temp=A[i+2]-A[i+1]
    if temp==0:
        cool=True
        for_last=True
        continue
    elif pre*temp<0 and cool:
        ans+=1
        if i==N-3 and for_last:
            ans-=1
        cool=False
        for_last=False
    else:
        cool=True
        for_last=False
    pre=temp
    
#print(for_last)
print(ans if for_last else ans+1)

Submission status: Wrong Answer

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

count = 0

status = 2

equal = 0
minus = 1
plus = 2


for i in range(n - 1):
    if status == equal:
        if a[i] < a[i+1]:
            status = plus
        elif a[i] > a[i+1]:
            status = minus 
    elif status == plus:
        if a[i] > a[i+1]:
            status = equal
            count += 1
    elif status == minus:
        if a[i] < a[i+1]:
            status = equal
            count +=1
print(count+1)

Submission status: Wrong Answer

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

cnt = 0

jug = 2
for i in range(n - 1):
    if jug == 2:
        if a[i] < a[i+1]:
            jug = 0
        elif a[i] > a[i+1]:
            jug = 1 
    elif jug == 0:
        if a[i] > a[i+1]:
            jug = 2
            cnt += 1
    elif jug == 1:
        if a[i] < a[i+1]:
            jug = 0
            cnt +=1
print(cnt+1)

Submission status: Wrong Answer

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

cnt = 0

if n == 0:
    print(1)
else:
    jug = 2
    for i in range(n - 1):
        if jug == 2:
            if a[i] < a[i+1]:
                jug = 0
            elif a[i] > a[i+1]:
                jug = 1 
        elif jug == 0:
            if a[i] > a[i+1]:
                jug = 2
                cnt += 1
        elif jug == 2:
            if a[i] < a[i+1]:
                jug = 0
                cnt +=1
    print(cnt+1)

Submission status: Wrong Answer

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

cnt = 0

if n == 0:
    print(0)
else:
    jug = 2
    for i in range(n - 1):
        if jug == 2:
            if a[i] < a[i+1]:
                jug = 0
            elif a[i] > a[i+1]:
                jug = 1 
        elif jug == 0:
            if a[i] > a[i+1]:
                jug = 2
                cnt += 1
        elif jug == 2:
            if a[i] < a[i+1]:
                jug = 0
                cnt +=1
    print(cnt+1)

Submission status: Wrong Answer

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

cnt = 0

jug = 2

for i in range(n - 1):
    if jug == 2:
        if a[i] < a[i+1]:
            jug = 0
        elif a[i] > a[i+1]:
            jug = 1 
    elif jug == 0:
        if a[i] > a[i+1]:
            jug = 2
            cnt += 1
    elif jug == 2:
        if a[i] < a[i+1]:
            jug = 0
            cnt +=1

print(cnt+1)

Submission status: Wrong Answer

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

cnt = 0

plus = 0
minus = 1
equal = 2

jug = equal

for i in range(n - 1):
    if jug == equal:
        if a[i] < a[i+1]:
            jug = plus
        elif a[i] > a[i+1]:
            jug = minus 
    elif jug == plus:
        if a[i] > a[i+1]:
            jug = minus
            cnt += 1
    elif jug == minus:
        if a[i] < a[i+1]:
            jug = plus
            cnt +=1

print(cnt+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
i = 0
while i < N-1:
  ans += 1
  tag = A[i]
  if tag == A[i+1]:
    while tag == A[i+1]:
      i += 1
      if i >= N - 1:
        break
  if tag < A[i+1]:
    #単調非減少
    while tag <= A[i+1]:
      tag = A[i+1]
      i += 1
      if i >= N - 1:
        break
    i += 1
    if i == N - 1:
      ans += 1
  else:
    #単調非増加
    while tag >= A[i+1]:
      tag = A[i+1]
      i += 1
      if i >= N - 1:
        break
    i += 1
    if i == N - 1:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
m=[]
m.append([A[0]])
j=0
f=True
if len(A) == 1:
  print(1)
  exit()
if A[0] > A[1]:
  f=False
for i in range(1,N):
  if A[i-1] <= A[i] and f:
    m[j].append(A[i])
  elif A[i-1] >= A[i] and not f:
    m[j].append(A[i])
  else:
    j+=1
    m.append([])
    m[j].append(A[i])
    if i != N-1:
      f=True if A[i] < A[i+1] else False
print(len(m))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
if n<=2:
    print(1)
    exit()
yt=[0]*n
for i in range(n-1):
    if l[i]<l[i+1]:
        yt[i]=1
    elif l[i]>l[i+1]:
        yt[i]=-1
    elif i!=0:
        yt[i]=yt[i-1]
ans=1
f=0
for i in range(n-1):
    if yt[i]*yt[i+1]==-1:
        ans+=1
        f+=1
    else:
        if f>0:
            ans-=f//2
        f=0
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
if n<=2:
    print(1)
    exit()
yt=[0]*n
for i in range(n-1):
    if l[i]<l[i+1]:
        yt[i]=1
    elif l[i]>l[i+1]:
        yt[i]=-1
    elif i!=0:
        yt[i]=yt[i-1]
ans=0
for i in range(n-1):
    if yt[i]*yt[i+1]==-1:
        ans+=1
        if i>1 and yt[i-1]*yt[i]==-1:
            ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
if n<=2:
    print(1)
    exit()
yt=[0]*n
for i in range(n-1):
    if l[i]<l[i+1]:
        yt[i]=1
    elif l[i]>l[i+1]:
        yt[i]=-1
    elif i!=0:
        l[i]=l[i-1]
ans=0
for i in range(n-1):
    if l[i]*l[i+1]==-1:
        ans+=1
        if i>1 and l[i-1]*l[i]==-1:
            ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
if n<=2:
    print(1)
    exit()
yt=[0]*n
for i in range(n-1):
    if l[i]<l[i+1]:
        yt[i]=1
    elif l[i]>l[i+1]:
        yt[i]=-1
    elif i!=0:
        l[i]=l[i-1]
ans=0
for i in range(n-1):
    if l[i]*l[i+1]==-1:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
if n<=2:
    print(1)
    exit()
yt=[]
for i in range(n-2):
    if l[i]<l[i+1]>=l[i+2] or l[i]>l[i+1]<=l[i+2]:
        yt.append(i+1)
yt.append(100000000)
ans=1
i=0
while len(yt)-1>i:
    if yt[i]+1==yt[i+1]:
        ans+=1
        i+=2
    else:
        ans+=1
        i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
if n<=2:
    print(1)
    exit()
yt=[]
for i in range(n-2):
    if l[i]<l[i+1]>=l[i+2] or l[i]>=l[i+1]<l[i+2]:
        yt.append(i+1)
yt.append(100000000)
ans=1
i=0
while len(yt)-1>i:
    if yt[i]+1==yt[i+1]:
        ans+=1
        i+=2
    else:
        ans+=1
        i+=1
print(ans)

Submission status: Wrong Answer

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

slash = 0
for i in range(n):
    if i <= n - 2 and a[i] < a[i + 1]: # up
        while i <= n - 2 and a[i] <= a[i + 1]:
            i += 1
        slash += 1
        continue
    elif i <= n - 2 and a[i] > a[i + 1]: # down
        while i <= n - 2 and a[i] >= a[i + 1]:
            i += 1
        slash += 1

print(slash + 1)

Submission status: Wrong Answer

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

slash = 0
if n >= 3:
    for i in range(n - 2):
        if a[i] < a[i + 1]:
            if a[i + 1] > a[i + 2]:
                slash += 1
        elif a[i] > a[i + 1]:
            if a[i + 1] < a[i + 2]:
                slash += 1
    if n >= 4 and a[n - 4] > a[n - 3] == a[n - 2] < a[n - 1]:
        slash += 1
    elif n >= 4 and a[n - 4] < a[n - 3] == a[n - 2] > a[n - 1]:
        slash += 1

print(slash + 1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a = list(map(int,input().split()))
cnt=1
index=2
while index<n:
    if (a[index]-a[index-1])*(a[index-1]-a[index-2])<0:
        cnt+=1
        index+=2
    else:
        index+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [x for x in map(int, input().split())]
i = 0
ans = 0
while i < len(A) - 2:
    if A[i] < A[i + 1] and A[i + 1] > A[i + 2]:
        ans += 1
        i = i + 2
        continue
    elif A[i] > A[i + 1] and A[i + 1] < A[i + 2]:
        ans += 1
        i = i + 2
        continue
    else:
        i += 1
ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
if n<=2:
    print(1)
    exit()
yt=[]
for i in range(n-2):
    if l[i]<l[i+1]>l[i+2] or l[i]>l[i+1]<l[i+2]:
        yt.append(i+1)
yt.append(100000000)
ans=1
i=0
while len(yt)-1>i:
    if yt[i]+1==yt[i+1]:
        ans+=1
        i+=2
    else:
        ans+=1
        i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 1
for i in range(1,n-1):
    if a[i-1] < a[i] > a[i+1]:
        ans += 1
    elif a[i-1] > a[i] < a[i+1]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))

if N==1:
    print(1)
    exit()

ans=0
pre=A[1]-A[0]
cool=True
for i in range(N-2):
    temp=A[i+2]-A[i+1]
    if temp==0:
        cool=True
        continue
    elif pre*temp<0 and cool:
        ans+=1
        cool=False
    else:
        cool=True
    pre=temp


print(ans+1)

Submission status: Wrong Answer

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

cnt = 0
pre_dif = 0
renzoku = False
for i in range(1,n):
    dif = a[i-1] - a[i]
    if dif == 0:
        renzoku = False
    elif (dif > 0) and (pre_dif < 0):
        if not renzoku:
            cnt += 1
            renzoku = True
        else:
            renzoku = False
    elif (dif < 0) and (pre_dif > 0):
        if not renzoku:
            cnt += 1
            renzoku = True
        else:
            renzoku = False
    else:
        renzoku = False
    pre_dif = dif 
print(cnt+1)

Submission status: Wrong Answer

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

cnt = 0
tmp = True 
for i in range(1,n-1):
    pre = a[i-1] - a[i]
    post = a[i] - a[i+1]
    if pre * post < 0 and tmp:
        cnt += 1
        tmp = False
    else:
        tmp = True
        
print(cnt+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=1
if n<=2:print(1);exit()
subt=a[1]-a[0]
for i in range(2,n):
  if subt*(a[i]-a[i-1])<0:
    ans+=1
  subt=a[i]-a[i-1]
print(ans)

Submission status: Wrong Answer

Solution code:

N=int(input())
A = list(map(int,input().split()))
if N==1:
    print(1)
    exit()

def chk(i,j):
    if i <=j:
        return 0
    else:
        return 1
    
ans=1
a=A.pop(0)
x = chk(a,A[0])

while A!=[]:
    b = A.pop(0)
    if x == 0 and a>b:
        ans+=1
        if A != []:
            x=chk(b,A[0])
        else:
            break
    elif x == 1 and a<=b:
        ans += 1
        if A != []:
            x=chk(b,A[0])
        else:
            break
    a=b
    
print(ans)

Submission status: Wrong Answer

Solution code:

N=int(input())
A = list(map(int,input().split()))
if N==1:
    print(1)
    exit()

def chk(i,j):
    if i <j:
        return 0
    else:
        return 1
    
ans=1
a=A.pop(0)
x = chk(a,A[0])

while A!=[]:
    b = A.pop(0)
    if x == 0 and a>=b:
        ans+=1
        if A != []:
            x=chk(b,A[0])
        else:
            break
    elif x == 1 and a<b:
        ans += 1
        if A != []:
            x=chk(b,A[0])
        else:
            break
    a=b
    
print(ans)

Submission status: Wrong Answer

Solution code:
#AGC13 A
N=int(input())
A = list(map(int,input().split()))
if N==1:
    print(1)
    exit()

def chk(i,j):
    if i <= j:
        return 0
    else:
        return 1
    
ans=1
a=A.pop(0)
x = chk(a,A[0])

while A!=[]:
    b = A.pop(0)
    if x == 0 and a>=b:
        ans+=1
        if A != []:
            x=chk(b,A[0])
        else:
            break
    elif x == 1 and a<=b:
        ans += 1
        if A != []:
            x=chk(b,A[0])
        else:
            break
    a=b
    
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))
if N==1:
    print(1)
    exit()

def chk(i,j):
    if i < j:
        return 0
    else:
        return 1
    
ans=1
a=A.pop(0)
x = chk(a,A[0])

while A!=[]:
    b = A.pop(0)
    if x == 0 and a>b:
        ans+=1
        if A != []:
            x=chk(b,A[0])
        else:
            break
    elif x == 1 and a<b:
        ans += 1
        if A != []:
            x=chk(b,A[0])
        else:
            break
    a=b
    
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))
if N==1:
    print(1)
    exit()

def chk(i,j):
    if i < j:
        return 0
    else:
        return 1
    
ans=1
a=A.pop(0)
x = chk(a,A[0])

while A!=[]:
    b = A.pop(0)
    if x == 0 and a>b:
        ans+=1
        if A != []:
            x=chk(b,A[0])
            a=b
        else:
            break
    elif x == 1 and a<b:
        ans += 1
        if A != []:
            a=b
            x=chk(b,A[0])
        else:
            break
    a=b
    
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))

if N == 1:
  print(1)
  exit()
def chk(i,j):
    if i < j:
        return 0
    else:
        return 1
    
ans=1
a=A.pop(0)
x = chk(a,A[0])

while A!=[]:
    b = A.pop(0)
    if x == 0 and a>b:
        ans+=1
        if A != []:
            x=chk(b,A[0])
        else:
            break
    elif x == 1 and a<b:
        ans += 1
        if A != []:
            x=chk(b,A[0])
        else:
            break
    a=b
    
print(ans)

Submission status: Wrong Answer

Solution code:
_ = input()
N = list(map(int, input().split()))
pren = N[0]
preud = 0 # up = 1, down = -1
cnt = 0
for n in N:
  # 初めに方向の評価
  if pren < n:
    ud = 1
  elif pren > n:
    ud = -1
  else:
    ud = 0
  # 逆方向
  if preud * ud == - 1:
    cnt += 1
  if ud != 0:
    preud = ud
  pren = n
#  print(ud, preud)
print(cnt+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

# 極値の数
ansF = 1
prev = -1
for i in range(1, N - 1):
    if A[i - 1] < A[i] and A[i + 1] < A[i]:
        if i - prev > 1:
            ansF += 1
            prev = i
    elif A[i - 1] > A[i] and A[i + 1] > A[i]:
        if i - prev > 1:
            ansF += 1
            prev = i

ansB = 1
prev = N + 1
for i in range(1, N - 1)[:: -1]:
    if A[i - 1] < A[i] and A[i + 1] < A[i]:
        if prev - i > 1:
            ansB += 1
            prev = i
    elif A[i - 1] > A[i] and A[i + 1] > A[i]:
        if prev - i > 1:
            ansB += 1
            prev = i

print(min(ansF, ansB))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

# 極値の数
ans = 1
i = 1
prev = -1
while i < N - 1:
    if A[i - 1] < A[i] and A[i + 1] < A[i]:
        if i - prev > 1:
            ans += 1
            prev = i
    elif A[i - 1] > A[i] and A[i + 1] > A[i]:
        if i - prev > 1:
            ans += 1
            prev = i
    i += 1

if prev < N - 1:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

# 極値の数
ans = 1
i = 1
prev = -1
while i < N - 1:
    if A[i - 1] < A[i] and A[i + 1] < A[i]:
        if i - prev > 1:
            ans += 1
            prev = i
    elif A[i - 1] > A[i] and A[i + 1] > A[i]:
        if i - prev > 1:
            ans += 1
            prev = i
    i += 1

if prev < N:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

# 極値の数
ans = 1
i = 1
prev = -1
while i < N - 1:
    if A[i - 1] < A[i] and A[i + 1] < A[i]:
        if i - prev > 1:
            ans += 1
            prev = i
    elif A[i - 1] > A[i] and A[i + 1] > A[i]:
        if i - prev > 1:
            ans += 1
            prev = i
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [float('inf')] + list(map(int, input().split())) + [float('inf')]

prev = 0
ans = 1
for i in range(1, N + 1):
    if A[i] < A[i - 1] and A[i] < A[i + 1]:
        if i - prev > 1:
            ans += 1
            prev = i

if prev < N:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

ans = 1
for i in range(1, N - 1):
    if (A[i] - A[i - 1]) * (A[i + 1] - A[i]) < 0:
        ans += 1

print(-(-ans // 2) + 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

left = 0
right = 0
ans = 0
while left < N:
    if left == N - 1:
        ans += 1
        break

    right = left + 1
    if A[left] < A[right]:
        while right < N and A[right - 1] < A[right]:
            right += 1
        ans += 1
    elif A[left] > A[right]:
        while right < N and A[right - 1] > A[right]:
            right += 1
        ans += 1
    left = right

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

# 極値の数
ans = 1
i = 1
while i < N - 1:
    if A[i - 1] < A[i] and A[i + 1] < A[i]:
        ans += 1
        i += 1
    elif A[i - 1] > A[i] and A[i + 1] > A[i]:
        ans += 1
        i += 1
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N,*A=map(int,open(0).read().split());f=a=0
for i,j in zip(A,A[1:]):
 if f:
  if(f<0)&(i<j)|(0>f)&(i>j):a+=1;f=0
 else:f=(i<j)-(i>j)
print(a+1)

Submission status: Wrong Answer

Solution code:
N,*A=map(int,open(0).read().split());h=a=0
for i,j in zip(A,A[1:]):
 if(0<h<i)&(i>j)|(h>i)&(i<j):a+=1;h=0
 else:h=i
print(a+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))

data = []
for i in range(N-1):
  if a[i+1]-a[i] == 0:
    continue
  else:
    data.append(a[i+1]-a[i])
#print(data)

if len(data) <= 1:
  print(0)
else:
  ans = 0
  left = 0
  i = 0
  while left < len(data)-1:
    if data[left]*data[left+1] < 0: # 極値
      ans += 1
      left += 1
      i = left
    left += 1
  else:
    if i == len(data):
      pass
    else:
      ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))

data = []
for i in range(N-1):
  if a[i+1]-a[i] == 0:
    continue
  else:
    data.append(a[i+1]-a[i])
#print(data)

if len(data) == 0:
  print(0)
else:
  ans = 0
  left = 0
  i = 0
  while left < len(data)-1:
    if data[left]*data[left+1] < 0: # 極値
      ans += 1
      left += 1
      i = left
    left += 1
  else:
    if i == len(data):
      pass
    else:
      ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))

data = []
for i in range(N-1):
  if a[i+1]-a[i] == 0:
    continue
  else:
    data.append(a[i+1]-a[i])
#print(data)

if len(data) == 0:
  print(0)
else:
  ans = 0
  left = 0
  i = 0
  while left < len(data)-1:
    if data[left]*data[left+1] < 0: # 極値
      ans += 1
      left += 1
      i = left
    left += 1
  else:
    if i == len(data)-1:
      pass
    else:
      ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
N,*A=map(int,open(0).read().split());print(1+sum((i>j)&(j<k)|(i<j)&(j>k)for i,j,k in zip(A,A[1:],A[2:]))-sum((i<j)&(j>k)&(k<l)for i,j,k,l in zip(A,A[1:],A[2:],A[3:])))

Submission status: Wrong Answer

Solution code:
N,*A=map(int,open(0).read().split());print(1+sum((i>j)&(j<k)|(i<j)&(j>k)for i,j,k in zip(A,A[1:],A[2:])))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
add = []
sub = []
even = []

for i in range(1, N):
    num = A[i-1] - A[i]
    if num < 0:
        add.append(num)
    elif num > 0:
        sub.append(num)
    else:
        even.append(num)

ans = min(len(add), len(sub))

if N % 2 != 0:
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
divide_num = 0
is_increase = None

for i in range(1, n):
  if a[i-1] is a[i]:
    continue
  if is_increase is None:
    is_increase = a[i-1] < a[i]
  if (a[i-1] < a[i]) != is_increase:
    divide_num += 1
    is_increase = None

print(divide_num+1)

Submission status: Wrong Answer

Solution code:
N = input()
N =int(N)
nums= list(map(int,input().split(" ")))
ans = 1
tend = 0
before = nums[0]
for a in nums[1:]:
    if (before - a) * tend < 0:
        tend = 0
        ans += 1
    else:
        tend = 1 if before - a > 0  else -1 if before - a < 0 else 0

    before = a

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
As = input().split()
for i in range(N):
    As[i] = int(As[i])
As = np.array(As)


def get_sign(x):
    if x>0:
        return +1
    elif x<0:
        return -1
    else:
        return 0

ans = 1
a0 = None
a1 = None
for a in As:
    if a0 is None:
        a0 = a
    elif a1 is None:
        a1 = a
    else:
        if get_sign(a-a1)==get_sign(a1-a0):
            a0 = a1
            a1 = a
        elif get_sign(a-a1)==0:
            pass
        else:
            ans += 1
            a0 = a
            a1 = None
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
As = input().split()
for i in range(N):
    As[i] = int(As[i])
As = np.array(As)


def get_sign(x):
    if x>0:
        return +1
    elif x<0:
        return -1
    else:
        return 0

ans = 1
a0 = None
a1 = None
for a in As:
    if a0 is None:
        a0 = a
    elif a1 is None:
        a1 = a
    else:
        if (get_sign(a-a1)==get_sign(a1-a0))|(get_sign(a-a1)==0):
            a0 = a1
            a1 = a
        else:
            ans += 1
            a0 = a
            a1 = None
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
As = input().split()
for i in range(N):
    As[i] = int(As[i])
As = np.array(As)


def get_sign(x):
    if x>0:
        return +1
    elif x<0:
        return -1
    else:
        return 0

ans = 1
a0 = None
a1 = None
for a in As:
    if a0 is None:
        a0 = a
    elif a1 is None:
        a1 = a
    else:
        if (get_sign(a-a1)==get_sign(a1-a0))|(get_sign(a1-a0)==0):
            a0 = a1
            a1 = a
        else:
            ans += 1
            a0 = a
            a1 = None
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
As = input().split()
for i in range(N):
    As[i] = int(As[i])
As = np.array(As)


def get_sign(x):
    if x>=0:
        return +1
    else:
        return -1
            
ans = 1
a0 = None
a1 = None
for a in As:
    if a0 is None:
        a0 = a
    elif a1 is None:
        a1 = a
    else:
        if get_sign(a-a1)==get_sign(a1-a0):
            a0 = a1
            a1 = a
        else:
            ans += 1
            a0 = a
            a1 = None
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
As = input().split()
for i in range(N):
    As[i] = int(As[i])
As = np.array(As)


def get_sign(x):
    if x>=0:
        return +1
    else:
        return -1
            
ans = 1
a0 = None
a1 = None
for a in As:
    if a0 is None:
        a0 = a
    elif a1 is None:
        a1 = a 
    else:
        if get_sign(a-a1)==get_sign(a1-a0):
            continue
        else:
            ans += 1
            a0 = a
            a1 = None
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N == 1:
  print(1)
else:
  result = 1
  d = 0
  for i in range(1, N):
    if A[i - 1] == A[i]:
      continue
    else:
      if d == 0:
        if A[i - 1] > A[i]:
          d = -1
        else:
          d = 1
      elif d == 1 and A[i - 1] > A[i]:
        d = -1
        result += 1
      elif d == -1 and A[i - 1] < A[i]:
        d = 1
        result += 1
  print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))

count = 1
mode = None
for i in range(n):
    if i+1 == n or arr[i+1] - arr[i] == 0:
        continue
    elif mode is None:
        if arr[i+1] - arr[i] == 1:
            mode = 'up'
        elif arr[i+1] - arr[i] == -1:
            mode = 'down'
    elif mode == 'up':
        if arr[i+1] - arr[i] != 1:
            count += 1
            mode = None
    elif mode == 'down':
        if arr[i+1] - arr[i] != -1:
            count += 1
            mode = None

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))

count = 1
mode = None
for i in range(n):
    if i+1 == n or arr[i+1] - arr[i] == 0:
        continue
    elif mode is None:
        if arr[i+1] - arr[i] == 1:
            mode = 'up'
        elif arr[i+1] - arr[i] == -1:
            mode = 'down'
    elif mode == 'up':
        if arr[i+1] - arr[i] != 1:
            count += 1
            mode = None
    elif mode == 'down':
        if arr[i+1] - arr[i-1] != -1:
            count += 1
            mode = None

print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    ix = 0
    cnt = 0
    while(ix < N):
        nix = ix
        minx = 0
        while(nix+1 < N and A[nix] <= A[nix+1]):
            minx += 1
            nix += 1
        nix = ix
        maxx = 0
        while(nix+1 < N and A[nix] >= A[nix+1]):
            minx += 1
            nix += 1
        ix = ix + max(minx, maxx) + 1
        
        cnt += 1

    print(cnt)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()