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 = int(input())
A = list(map(int,input().split()))
t = 0
i = 1
for _ in range(1, n - 1):
    if (A[i - 1] >= A[i] >= A[i+1]) or (A[i-1] <= A[i] <= A[i+1]):
        i += 1
    else:
        t += 1
        i += 2
    if i>=n-1:
        break
print(t + 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.append(A[-1])
t = 0
i = 1
for _ in range(1, n - 1):
    if (A[i - 1] >= A[i] >= A[i+1]) or (A[i-1] <= A[i] <= A[i+1]):
        i += 1
    else:
        t += 1
        i += 2
    if i>=n-1:
        break
print(t + 1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=1
i=0
res=-2
if n>3:
    a1,a2=a[2]-a[1],a[1]-a[0]
    while i<n-2:
        if a[i+2]-a[i+1]!=0:
            a1=a[i+2]-a[i+1]
        if a[i+1]-a[i]!=0:
            a2=a[i+1]-a[i]
        if a1*a2<0 and i-res>=2:
            ans+=1
            res=i
        i+=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
*a,=map(int,input().split())
cnt=0
mode=0
for i in range(n-1):
    if mode==0:
        if a[i]<a[i+1]:
            cnt+=1
            mode="inc"
        elif a[i]>a[i+1]:
            cnt+=1
            mode="dec"
    if a[i]<a[i+1]:
        if mode=="inc":
            pass
        else:
            mode=0
    elif a[i]>a[i+1]:
        if mode=="dec":
            pass
        else:
            mode=0
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
*a,=map(int,input().split())
cnt=0
mode=0
for i in range(n-1):
    if mode==0:
        if a[i]<a[i+1]:
            mode="inc"
        else:
            mode="dec"
    if a[i]<a[i+1]:
        if mode=="inc":
            pass
        else:
            cnt+=1
            mode=0
    elif a[i]>a[i+1]:
        if mode=="dec":
            pass
        else:
            cnt+=1
            mode=0
if cnt==0:
    print(0)
else:
    print(cnt+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
*a,=map(int,input().split())
cnt=0
mode=0
for i in range(n-1):
    if mode==0:
        if a[i]<a[i+1]:
            mode="inc"
        else:
            mode="dec"
    if a[i]<a[i+1]:
        if mode=="inc":
            pass
        else:
            cnt+=1
            mode=0
    elif a[i]>a[i+1]:
        if mode=="dec":
            pass
        else:
            cnt+=1
            mode=0
print(cnt+1)

Submission status: Wrong Answer

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

count = 1
flag = False
for i in range(1, n-1):
    if flag:
        flag = False
        continue
    if (a[i] > a[i-1] and a[i] > a[i+1]) or (a[i] < a[i-1] and a[i] < a[i+1]):
        count += 1
        flag = True
print(count)

Submission status: Wrong Answer

Solution code:
#AGC 013 A - Sorted Arrays
#増加⇔減少に転じる際、Ai+1 - Aiは必ず符号反転することを利用
N = int(input())
A = list(map(int,input().split()))

count = 0
sign = 0
for i in range(N-1):
    if sign == 0:
        sign = A[i+1]-A[i]
    elif sign*(A[i+1]-A[i]) < 0:
        count += 1
        sign = 0
print(count)

Submission status: Wrong Answer

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

ans1 = 1
ans2 = 1
c = 0
c1 = 0
for i in range(1, n):
    if a[i] > a[i-1]:
        c1 = 1
    elif a[i] < a[i-1]:
        c1 = -1
    if c != 0 and c != c1:
        ans1 += 1
        c = 0
        continue
    c = c1

for i in range(1, n):
    if a[n-i-1] > a[n-i]:
        c1 = 1
    elif a[n-i-1] < a[n-i]:
        c1 = -1
    if c != 0 and c != c1:
        ans2 += 1
        c = 0
        continue
    c = c1

print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int,input().split()))
pops = []

if len(b) == 1:
    print(1)
    exit(0)
ans = 0

mnd = True
first = True
for i in range(1,len(b)):
    if b[i-1] == b[i]:
        continue
    if first and b[i] != b[i-1]:
        mnd = b[i-1] < b[i]
        first = False
    if mnd and b[i-1] > b[i]:
        ans += 1
        mnd = i<len(b)-1 and b[i] < b[i+1]
    elif (not mnd) and b[i-1]<b[i]:
        ans += 1
        mnd = i<len(b)-1 and b[i] < b[i+1]
print(ans+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int,input().split()))
pops = []

if len(b) == 1:
    print(1)
    exit(0)
ans = 0
sb = list(set(b))
if len(sb) == 1:
    print(1)
    exit(0)
mnd = True
first = True
for i in range(1,len(b)):
    if b[i-1] == b[i]:
        continue
    if first and b[i] != b[i-1]:
        mnd = b[i-1] < b[i]
        first = False
    if mnd and b[i-1] > b[i]:
        ans += 1
        mnd = i<len(b)-1 and b[i] < b[i+1]
    elif (not mnd) and b[i-1]<b[i]:
        ans += 1
        mnd = i<len(b)-1 and b[i] < b[i+1]
print(ans+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int,input().split()))
pops = []

if len(b) == 1:
    print(1)
    exit(0)
ans = 0
sb = list(set(b))
if len(sb) == 1:
    print(1)
    exit(0)
mnd = sb[0] < sb[1]
for i in range(1,len(b)):
    if b[i-1] == b[i]:
        continue
    if mnd and b[i-1] > b[i]:
        ans += 1
        mnd = i<len(b)-1 and b[i] < b[i+1]
    elif (not mnd) and b[i-1]<b[i]:
        ans += 1
        mnd = i<len(b)-1 and b[i] < b[i+1]
print(ans+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int,input().split()))
pops = []

if len(b) == 1:
    print(1)
    exit(0)
ans = 0
mnd = b[0] < b[1]
for i in range(1,len(b)):
    if b[i-1] == b[i]:
        continue
    if mnd and b[i-1] > b[i]:
        ans += 1
        mnd = i<len(b)-1 and b[i] < b[i+1]
    elif (not mnd) and b[i-1]<b[i]:
        ans += 1
        mnd = i<len(b)-1 and b[i] < b[i+1]
print(ans+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
pops = []
for i in range(1,n):
    if a[i] == a[i-1]:
        pops.append(i)
b = []
for i in range(n):
    if i in pops:
        continue
    b.append(a[i])
if len(b) == 1:
    exit(0)
ans = 0
mnd = b[0] < b[1]
for i in range(1,len(b)):
    if mnd and b[i-1] > b[i]:
        ans += 1
        mnd = i<len(b)-1 and b[i] < b[i+1]
    elif (not mnd) and b[i-1]<b[i]:
        ans += 1
        mnd = i<len(b)-1 and b[i] < b[i+1]
print(ans+1)

Submission status: Wrong Answer

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

ans = 1
c = 0
c1 = 0
for i in range(1, n):
    if a[i] > a[i-1]:
        c1 = 1
    elif a[i] < a[i-1]:
        c1 = -1
    if c != 0 and c != c1:
        ans += 1
        c = 0
        continue
    c = c1

print(ans)

Submission status: Wrong Answer

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

ans = 1
c = 0
c1 = 0
for i in range(1, n):
    if a[i] > a[i-1]:
        c1 = 1
    elif a[i] < a[i-1]:
        c1 = -1
    if c != c1 and c != 0:
        ans += 1
        c = 0
        c1 = 0
        continue
    c = c1
    c1 = 0

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
pops = []
for i in range(1,n):
    if a[i] == a[i-1]:
        pops.append(i)
b = []
for i in range(n):
    if i not in pops:
        b.append(a[i])
        

ans = 0
mnd = True
for i in range(1,n):
    if mnd and a[i-1] > a[i]:
        ans += 1
        mnd = i<n-1 and a[i] < a[i+1]
    elif (not mnd) and a[i-1]<a[i]:
        ans += 1
        mnd = i<n-1 and a[i] < a[i+1]
temp = 0
mnd = False
for i in range(1,n):
    if mnd and a[i-1] > a[i]:
        temp += 1
        mnd = i<n-1 and a[i] < a[i+1]
    elif (not mnd) and a[i-1]<a[i]:
        temp += 1
        mnd = i<n-1 and a[i] < a[i+1]
print(min(ans,temp)+1)

Submission status: Wrong Answer

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

ans = 1
c = 0
for i in range(1, n):
    if a[i] > a[i-1]:
        c1 = 1
    elif a[i] < a[i-1]:
        c1 = -1
    else:
        c1 = 0
    if c != c1 and c != 0:
        ans += 1
        c = 0
        continue
    c = c1

print(ans)

Submission status: Wrong Answer

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

ans = 1
c = 0
for i in range(1, n):
    if a[i] > a[i-1]:
        c1 = 1
    elif a[i] < a[i-1]:
        c1 = -1
    else:
        c1 = 0
    if c != c1 and c != 0:
        ans += 1
        c = 0
        continue
    c = c1

Submission status: Wrong Answer

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

ans = 0
c = 0
c1 = 0
for i in range(1, n):
    if a[i] > a[i-1]:
        c1 = 1
    elif a[i] < a[i-1]:
        c1 = -1
    if c != c1 and c != 0:
        ans += 1
        c = 0
        continue
    c = c1

print(ans+1)

Submission status: Wrong Answer

Solution code:
N=int(input())
count=1
size=1
p=list(map(int,input().split()))
q=[p[0]]
for i in range (1,N):
  if p[i]!=p[i-1]:
    q.append(p[i])
    size+=1
j=0
while True:
  if j>=size-2:
    break
  while (q[j]-q[j+1])*(q[j+1]-q[j+2])>=0:
    if j>=size-3:
      count+=1
      break
    j+=1    
  count+=1
  j+=2
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
count=1
size=1
p=list(map(int,input().split()))
q=[p[0]]
for i in range (1,N):
  if p[i]!=p[i-1]:
    q.append(p[i])
    size+=1
j=0
while True:
  if j>=size-2:
    break
  while (q[j]-q[j+1])*(q[j+1]-q[j+2])>=0:
    if j>=size-3:
      break
    j+=1    
  count+=1
  j+=2
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
count=1
size=1
p=list(map(int,input().split()))
q=[p[0]]
for i in range (1,N):
  if p[i]!=p[i-1]:
    q.append(p[i])
    size+=1
j=0
while True:
  if j>=size-2:
    break
  while (q[j]-q[j+1])*(q[j+1]-q[j+2])>=0:
    j+=1
    if j>=size-2:
      break
  count+=1
  j+=2
print(count)

Submission status: Wrong Answer

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

word = []
count = 0
start = 0
for x in range(N):
    if start==N:
#         print("break")
        break
    for i in range(N,1,-1):
        word = A[start:i]
        if word == sorted(word, reverse=True):
            count += 1
            start = i
#             print(word)
#             print(start)
            break
        elif word== sorted(word, reverse=False):
            count += 1
            start = i
#             print(word)
#             print(start)
            break
            
print("{}".format(count))

Submission status: Wrong Answer

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

word = []
count = 0
start = 0
for x in range(N):
    if start==N:
        print("break")
        break
    for i in range(N,1,-1):
        word = A[start:i]
        if word == sorted(word, reverse=True):
            count += 1
            start = i
            print(word)
            print(start)
            break
        elif word== sorted(word, reverse=False):
            count += 1
            start = i
            print(word)
            print(start)
            break
            
print("{}".format(count))

Submission status: Wrong Answer

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

word = []
count = 0
start = 0
for x in range(N):
    if start==N:
        break
    for i in range(N,1,-1):
        word = A[start:i]
        if word == sorted(word, reverse=True) or word== sorted(word, reverse=False):
            count += 1
            start = i
            break
            
print("{}".format(count))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


#----------
N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#----------
flag_plus_minus = ""
count = 0
for i in range(len(A_list)-1):
    diff = A_list[i+1] - A_list[i]
    
    if flag_plus_minus == "" :
        flag_plus_minus = str((diff > 0) - (diff < 0))
        count += 1

    if flag_plus_minus != "" and A_list[i] != A_list[i+1] :
        if ( diff * int(flag_plus_minus) ) < 0:
            flag_plus_minus = ""
            
            if i == (len(A_list)-1) - 1:
                count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
if n == 1:
    print(1)
    exit()
if l[-1] >= l[-2]:
    l += [-float('Inf')]
else:
    l += [float('Inf')]
ans = []
turn = "neutral"
start = 0
end = 0
#print(*l)
for i in range(n):
    if turn == "neutral":
        if l[i] >= l[i+1]:
            turn = "decrease"
        else:
            turn = "increase"
    else:
        if l[i] >= l[i+1]:
            if turn == "decrease":
                continue
            else:
                end = i
                ans.append(l[start:end+1])
                start = i + 1
                turn = "neutral"
        else:# l[i] <= l[i]
            if turn == "increase":
                continue
            else:
                end = i
                ans.append(l[start:end+1])
                start = i + 1
                turn = "neutral"
#print(i,turn)
if end != n - 1:
    ans += [l[start:]]
print(len(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
if n == 1:
    print(1)
    exit()
if l[-1] >= l[-2]:
    l += [-float('Inf')]
else:
    l += [float('Inf')]
ans = []
turn = "neutral"
start = 0
end = 0
for i in range(n):
    if turn == "neutral":
        if l[i] >= l[i+1]:
            turn = "decrease"
        else:
            turn = "increase"
    else:
        if l[i] >= l[i+1]:
            if turn == "decrease":
                continue
            else:
                end = i
                ans.append(l[start:end+1])
                start = i + 1
                end = i + 1
                turn = "neutral"
        else:# l[i] <= l[i]
            if turn == "increase":
                continue
            else:
                end = i
                ans.append(l[start:end+1])
                start = i + 1
                end = i + 1
                turn = "neutral"
print(len(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
if n == 1:
    print(1)
    exit()
if l[-1] >= l[-2]:
    l += [float('Inf')]
else:
    l += [-float('Inf')]
ans = 1
i = 1
while i <= n - 1:
    if l[i-1] <= l[i] and l[i] <= l[i+1]:
        i += 1
    elif l[i-1] >= l[i] and l[i] >= l[i+1]:
        i += 1
    else:
        ans += 1
        i += 2      
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
if n == 1:
    print(1)
    exit()
if l[-1] >= l[-2]:
    l += [float('Inf')]
else:
    l += [-float('Inf')]
ans = 1
i = 1
while i <= n - 1:
    if l[i-1] <= l[i] and l[i] <= l[i+1]:
        i += 1
    elif l[i-1] >= l[i] and l[i] >= l[i+1]:
        i += 1
    else:
        #print(l[i-1],l[i],l[i+1])
        ans += 1
        i += 2
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
r = 0
for i in range(1, n-1):
    t = (A[i-1]-A[i])*(A[i]-A[i+1])
    if t < 0:
        r += 1
        A[i]=A[i+1]
print(0 if r==0 else r+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
r = 1
for i in range(1, n-1):
    t = (A[i-1]-A[i])*(A[i]-A[i+1])
    if t < 0:
        r += 1
        A[i]=A[i+1]
print(r)

Submission status: Wrong Answer

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

flag1 = True
flag2 = False
if n <= 2:
  print(1)
else:
  count = 1
  for i in range(n-1):
    if a[i] - a[i+1] < 0:
      flag1 = True
    elif a[i] - a[i+1] > 0:
      flag2 = True
 
    if flag1 and flag2:
      count+=1
      flag1 = False
      flag2 = False
  print(count)

Submission status: Wrong Answer

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

ans = 1

judge = 0
for i in range(n-1):
  if a[i] == a[i+1]:
    break
  elif a[i] < a[i+1]:
    if judge == -1:
      ans += 1
    else:
      judge = 1
  elif a[i] > a[i+1]:
    if judge == 1:
      ans += 1
    else:
      judge = 1      
print(ans)

Submission status: Wrong Answer

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

ans = 1
judge = -1
for i in range(n-1):
  if a[i] == a[i+1]:
    break
  elif a[i] < a[i+1]:
    if judge == -1:
      ans += 1
    else:
      judge = 1
  elif a[i] > a[i+1]:
    if judge == 1:
      ans += 1
    else:
      judge = 1      
print(ans)

Submission status: Wrong Answer

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

count = 0
i = 0
while(i < n-2):
  if a[i] < a[i+1] and a[i+1] > a[i+2]:
    i+=1
    count+=1
  elif a[i] > a[i+1] and a[i+1] < a[i+2]:
    i+=1
    count+=1
  i+=1
print(count+1)

Submission status: Wrong Answer

Solution code:
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
方針
#差分をとって、0を抜いた数列をつくる
    これにて非単調減少・増加を単調増加、単調減少として捉えられる
#隣り合う2つ正負が違うなら積は負になるので
#負になった2つの間で切ればよい
"""
#solution:
#潜 影 蛇 手 ! !
N=int(input())
A=list(pin())
B=[]
for i in range(N):
    if A[i]!=0:
        B.append(A[i])
C=[1-2*(B[j+1]>B[j])for j in range(len(B)-1)]
k=0
ans=0

while(k<len(C)-1):
    if C[k+1]*C[k]<0:
        #print("crak:",k+1)
        k+=1
        ans+=1
    k+=1
print(ans+1)
#print(["NO","YES"][1-cond])
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])

Submission status: Wrong Answer

Solution code:

#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
方針
#差分をとって、0を抜いた数列をつくる
    これにて非単調減少・増加を単調増加、単調減少として捉えられる
#隣り合う2つ正負が違うなら積は負になるので
#負になった2つの間で切ればよい
"""
#solution:
#潜 影 蛇 手 ! !
N=int(input())
A=list(pin())
B=[]
for i in range(N):
    if A[i]!=0:
        B.append(A[i])
C=[(B[j+1]>B[j])-0.5 for j in range(len(B)-1)]
k=0
ans=0

while(k<len(C)-1):
    if C[k+1]*C[k]<0:
        #print("crak:",k+1)
        k+=1
        ans+=1
    k+=1
print(ans+1)

Submission status: Wrong Answer

Solution code:
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
方針
#差分をとって、0を抜いた数列をつくる
    これにて非単調減少・増加を単調増加（要素が正）、単調減少（要素が負）として捉えられる
#隣り合う2つ正負が違うなら積は負になるので
#負になった2つの間で切ればよい
"""
#solution:
#潜 影 蛇 手 ! !
N=int(input())
A=list(pin())
B=[]
for i in range(N):
    if A[i]!=0:
        B.append(A[i])
C=[B[j+1]-B[j] for j in range(N-1)]
k=0
ans=0

while(k<len(C)-1):
    if C[k+1]*C[k]<0:
        #print("crak:",k+1)
        k+=1
        ans+=1
    k+=1
print(ans+1)

Submission status: Wrong Answer

Solution code:
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？

#solution:
def comp(p):#期待値
    return ((p+1)/2)
#潜 影 蛇 手 ! !
N=int(input())
A=list(pin())
B=[]
for i in range(N):
    if A[i]!=0:
        B.append(A[i])
C=[B[j+1]-B[j] for j in range(N-1)]
k=0
ans=0
while(k<len(C)-1):
    if C[k+1]*C[k]<0:
        #print("crak:",k+1)
        k+=1
        ans+=1
    k+=1
print(ans+1)
#print(["NO","YES"][1-cond])
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])

Submission status: Wrong Answer

Solution code:
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？

#solution:
def comp(p):#期待値
    return ((p+1)/2)
#潜 影 蛇 手 ! !
N=int(input())
A=list(pin())
B=[A[i+1]-A[i] for i in range(N-1)]
ans=0
k=1
while(k<N-1):
    #print(k)
    if B[k]*B[k-1]<0:
        #print("crak:",k+1)
        k+=1
        ans+=1
    k+=1
print(ans+1)
#print(["NO","YES"][1-cond])
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])

Submission status: Wrong Answer

Solution code:
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？

#solution:
def comp(p):#期待値
    return ((p+1)/2)
#潜 影 蛇 手 ! !
N=int(input())
A=list(pin())
B=[A[i+1]-A[i] for i in range(N-1)]
ans=0
k=1
while(k<N-1):
    if B[k]*B[k-1]==-1:
        k+=1
        ans+=1
    k+=1
print(ans+1)

Submission status: Wrong Answer

Solution code:
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？

#solution:
def comp(p):#期待値
    return ((p+1)/2)
#潜 影 蛇 手 ! !
N=int(input())
A=list(pin())
B=[A[i+1]-A[i] for i in range(N-1)]
ans=0
k=1
while(k<N-1):
    print(k)
    if B[k]*B[k-1]==-1:
        k+=1
        ans+=1
    k+=1
print(ans+1)

Submission status: Wrong Answer

Solution code:
def my_sign(n):
    return (n > 0) - (n < 0)

N = int(input())
A_lst = [int(x) for x in input().split()]
cnt = 1
if N == 1:
    pass
else:
    S_lst = []
    for i in range(1, N):
        S_lst.append(my_sign(A_lst[i] - A_lst[i - 1]))
    for i in range(len(S_lst)):
        if i == 0 and S_lst[i] == 0:
            for j in range(len(S_lst)):
                if not S_lst[j] == 0:
                    S_lst[i] = S_lst[j]
        elif S_lst[i] == 0:
            S_lst[i] = S_lst[i - 1]
    i = 0
    pm = S_lst[i]
    while i < len(S_lst):
        if i == 0:
            i += 1
        elif S_lst[i] == pm:
            i += 1
        else:
            cnt += 1
            i += 1
            if i < len(S_lst):
                pm = S_lst[i]
print(cnt)

Submission status: Wrong Answer

Solution code:
def my_sign(n):
    return (n > 0) - (n < 0)
def kugiri(cnt, lst):
    if len(lst) <= 1:
        return cnt
    else:
        pm = lst[0]
        i = 1
        fl = 0
        while i < len(lst):
            if pm == lst[i]:
                i += 1
                continue
            else:
                fl = 1
                break
        if fl == 1:
            new_lst = []
            for j in range(i + 1, len(lst)):
                new_lst.append(lst[j])
            return kugiri(cnt + 1, new_lst)
        else:
            return cnt

N = int(input())
A_lst = [int(x) for x in input().split()]
cnt = 1
if N == 1:
    pass
else:
    S_lst = []
    for i in range(1, N):
        S_lst.append(my_sign(A_lst[i] - A_lst[i - 1]))
    for i in range(len(S_lst)):
        if i == 0 and S_lst[i] == 0:
            for j in range(len(S_lst)):
                if not S_lst[j] == 0:
                    S_lst[i] = S_lst[j]
        elif S_lst[i] == 0:
            S_lst[i] = S_lst[i - 1]
    i = 0
    pm = S_lst[i]
    while i < len(S_lst):
        if i == 0:
            i += 1
        elif S_lst[i] == pm:
            i += 1
        else:
            cnt += 1
            i += 1
            if i >= len(S_lst):
                break
            pm = S_lst[i]
print(cnt)

Submission status: Wrong Answer

Solution code:
def my_sign(n):
    return (n > 0) - (n < 0)
def kugiri(cnt, lst):
    if len(lst) <= 1:
        return cnt
    else:
        pm = lst[0]
        i = 1
        fl = 0
        while i < len(lst):
            if pm == lst[i]:
                i += 1
                continue
            else:
                fl = 1
                break
        if fl == 1:
            new_lst = []
            for j in range(i + 1, len(lst)):
                new_lst.append(lst[j])
            return kugiri(cnt + 1, new_lst)

N = int(input())
A_lst = [int(x) for x in input().split()]
cnt = 1
if N == 1:
    pass
else:
    S_lst = []
    for i in range(1, N):
        S_lst.append(my_sign(A_lst[i] - A_lst[i - 1]))
    for i in range(len(S_lst)):
        if i == 0 and S_lst[i] == 0:
            for j in range(len(S_lst)):
                if not S_lst[j] == 0:
                    S_lst[i] = S_lst[j]
        elif S_lst[i] == 0:
            S_lst[i] = S_lst[i - 1]
    cnt = kugiri(cnt, S_lst)
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_lst = [int(x) for x in input().split()]
B_lst =[]
for i in range(N - 1):
    B_lst.append(A_lst[i + 1] - A_lst[i])

def my_sign(n):
    return (n > 0) - (n < 0)

cnt = 1
i = 0
while True:
    if i >= len(B_lst) - 1:
        break
    if my_sign(B_lst[i]) == 0 or my_sign(B_lst[i + 1]) == 0:
        i += 1
        continue
    elif my_sign(B_lst[i]) == my_sign(B_lst[i + 1]):
        i += 1
        continue
    else:
        cnt += 1
        i +=2
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_lst = [int(x) for x in input().split()]
B_lst =[]
for i in range(N - 1):
    B_lst.append(A_lst[i + 1] - A_lst[i])

def my_sign(n):
    return (n > 0) - (n < 0)

cnt = 1
i = 0
while True:
    if i >= len(B_lst) - 1:
        break
    if my_sign(B_lst[i]) == 0 or my_sign(B_lst[i + 1]) == 0:
        i += 1
        continue
    if my_sign(B_lst[i]) == my_sign(B_lst[i + 1]):
        i += 1
        continue
    else:
        cnt += 1
        i +=2
print(cnt)

Submission status: Wrong Answer

Solution code:

N = int(input())

A = list(map(int,input().split()))

ans = 1
f = False

for i in range(N-2):

    i += 1

    if f:
        f = False
        continue

    if A[i-1] > A[i] and A[i] < A[i+1]:
        ans += 1
        f = True

    elif A[i-1] < A[i] and A[i] > A[i+1]:
        ans += 1
        f = True

print (ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
if n == 1:
    print(1)
    exit()
if l[-1] > l[-2]:
    l += [float('Inf')]
else:
    l += [-float('Inf')]
ans = 1
i = 1
while i <= n - 1:
    if l[i-1] <= l[i] and l[i] <= l[i+1]:
        i += 1
    elif l[i-1] >= l[i] and l[i] >= l[i+1]:
        i += 1
    else:
        #print(l[i-1],l[i],l[i+1])
        ans += 1
        i += 2
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
current = "n"
ans = 1
for i in range(n-1):
    if a[i] >= a[i+1]:
        if current == "n":
            current = "d"
        elif current == "u":
            ans += 1
            current = "n"
            #print(a[0:i+1],a[i+1:])
        else:
            continue
    else:
        if current == "n":
            current = "u"
        elif current == "d":
            ans += 1
            current = "n"
            #print(a[0:i],a[i+1:])
        else:
            continue
print(ans)

Submission status: Wrong Answer

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

# dp table
INF = float('inf')
dp = [INF]*N
dp[0] = 0
inc, dec = 0, 0

for i in range(1,N):
    if A[i] >= A[i-1]:
        inc += 1
    else:
        inc = 1
    if A[i] <= A[i-1]:
        dec += 1
    else:
        dec = 1
    dp[i] = min(dp[i-inc] + 1, dp[i-dec] + 1)
print(dp[N-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
if N < 3:
    print(1)
else:
    ans = 1
    last = Alist[0]
    new_a = [last]
    for i in range(N):
        now = Alist[i]
        if now != last:
            new_a.append(now)
        last = now
    now = "up" if new_a[0] < new_a[1] else "down"
    f = now
    for i in range(1, len(new_a)):
        if new_a[i - 1] == new_a[i]:
            continue
        elif new_a[i - 1] < new_a[i]:
            if now == "down":
                now = "up"
                if now != f:
                    ans += 1
        elif new_a[i - 1] > new_a[i]:
            if now == "up":
                now = "down"
                if now != f:
                    ans += 1
        # print(i, now, ans)
    print(ans + 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    add = 0
    ans = 1
    i = 0
    while i < N-1:
        if add == 0:
            add = 1 if A[i] < A[i + 1] else -1
        elif add == 1:
            if A[i] > A[i + 1]:
                add = 0
                ans += 1
        else:
            if A[i] < A[i+1]:
                add = 0
                ans += 1
        i += 1
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
if N < 3:
    print(1)
else:
    ans = 1
    last = Alist[0]
    new_a = [last]
    for i in range(N):
        now = Alist[i]
        if now != last:
            new_a.append(now)
        last = now
    now = "up" if new_a[0] < new_a[1] else "down"
    for i in range(1, len(new_a)):
        if new_a[i - 1] == new_a[i]:
            continue
        elif new_a[i - 1] < new_a[i]:
            if now == "down":
                now = "up"
                ans += 1
        elif new_a[i - 1] > new_a[i]:
            if now == "up":
                now = "down"
        # print(i, now, ans)
    print(ans + 1)