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()))
ans=1
temp=0
for i in range(1,n):
  if a[i-1]<a[i] and temp==0:
    temp=1
  elif a[i-1]>a[i] and temp==0:
    temp=2
  elif a[i-1]>a[i] and temp==1:
    temp=2
    ans=ans+1
  elif a[i-1]<a[i] and temp==2:
    temp=1
    ans=ans+1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
flg = ""
before_flg = ""
for i in range(n-1):
    if a[i+1] > a[i]:
        flg = "up"
    elif a[i+1] < a[i]:
        flg = "down"
    else:
        flg = ""
    if before_flg == "up" and flg == "down" or before_flg == "down" and flg == "up":
        ans +=1
        before_flg = ""
    else:
        before_flg = flg
print(ans+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))

    res = []
    mode = 0
    previous = 0
    flag = False

    for i in range(1, len(A) - 1):
        if flag:
            flag = False
            continue
        if mode == 0:
            if A[i - 1] < A[i]:
                mode = 1
            elif A[i -1] > A[i]:
                mode = -1
        if mode == 1 and A[i] > A[i + 1]:
            res.append(A[previous:i + 1])
            previous = i + 1
            mode = 0
            flag = True
        elif mode == -1 and A[i] < A[i + 1]:
            res.append(A[previous:i + 1])
            previous = i + 1
            mode = 0
            flag = True

    if mode == 0:
        print(len(res) + 1)
    else:
        print(len(res))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def solve():
  n = int(input())
  a = list(map(int, input().split()))
  state, cut = -1, 0
  for i in range(n-1):
    #print(i, cut, state)
    if a[i] < a[i+1]:
      if state != 1:
        cut += 1
      state = 1
    else:
      if state != 0:
        cut += 1
      state = 0
  print(cut)
  return 0
 
if __name__ == "__main__":
  solve()

Submission status: Wrong Answer

Solution code:
def solve():
  n = int(input())
  a = list(map(int, input().split()))
  state, cut = -1, 0
  for i in range(n-1):
    #print(i, cut, state)
    if a[i] < a[i+1]:
      if state != 1:
        cut += 1
      state = 1
    else:
      if state != 0:
        cut += 1
      state = 0
  return 0
 
if __name__ == "__main__":
  solve()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=iter(map(int,input().split()))
p=1
i,j=next(a),next(a,0)
while i!=0:
    k=next(a,0)
    #print(j,k)
    if 0 not in (i,j,k) and (i<j>k or i>j<k):
        p+=1
        i,j=j,k
        k=next(a,0)
    i,j=j,k
print(p)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=iter(map(int,input().split()))
p=1
i,j=next(a),next(a,0)
while j!=0:
    k=next(a,0)
    #print(j,k)
    if 0 not in (i,j,k) and (i<j>k or i>j<k):
        p+=1
        i,j=j,k
        k=next(a,0)
    i,j=j,k
print(p)

Submission status: Wrong Answer

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

now = 'E'
cnt = 1
for i in range(1, N):
    if alst[i] > alst[i-1]:
        new = 'U' #up
    elif alst[i] < alst[i-1]:
        new = 'D' #down
    else:
        new = 'E'

    if now == new or now == 'E':
        now = new
    elif now != new :
        cnt += 1
        now = 'E'
print(cnt)

Submission status: Wrong Answer

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

now = 'increase' or 'decrease'
cnt = 1
for i in range(1, N):
    x = now
    if alst[i] - alst[i - 1] > 0:
        tmp = 'increase'
    else:
        tmp = 'decrease'

    if tmp != x:
        cnt += 1
        x = tmp

print(cnt)

Submission status: Wrong Answer

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

x = 'increase' or 'decrease'
cnt = 1
for i in range(1, N):
    if alst[i] - alst[i - 1] > 0:
        tmp = 'increase'
    else:
        tmp = 'decrease'

    if tmp != x:
        cnt += 1
    x = tmp

print(cnt)

Submission status: Wrong Answer

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

l1 = list()
for i in range(1, n):
    if l[i] > l[i-1]:
        l1.append(1)
    elif l[i] == l[i-1]:
        l1.append(0)
    else:
        l1.append(-1)

ans = 0

for i in range(n-1):
    if l1[i] != 0:
        c = l1[i]
        break

i = 0
while i <= n-3:
    if c*l1[i+1] == -1:
        ans += 1
        if i < n-3:
            c = l1[i+2]
        i += 2
    else:
        i += 1

print(ans + 1)

Submission status: Wrong Answer

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

l1 = list()
for i in range(1, n):
    if l[i] > l[i-1]:
        l1.append(1)
    elif l[i] == l[i-1]:
        l1.append(0)
    else:
        l1.append(-1)

print(l1)
ans = 0

for i in range(n-1):
    if l1[i] != 0:
        c = l1[i]
        break

i = 0
while i <= n-3:
    if c*l1[i+1] == -1:
        ans += 1
        if i < n-3:
            c = l1[i+2]
        i += 2
    else:
        i += 1

print(ans + 1)

Submission status: Wrong Answer

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

l1 = list()
for i in range(1, n):
    if l[i] > l[i-1]:
        l1.append(1)
    elif l[i] == l[i-1]:
        l1.append(0)
    else:
        l1.append(-1)

ans = 0
i = 1
while i <= n-2:
    if l1[i]*l1[i-1] == -1:
        ans += 1
        i += 2
    else:
        i += 1

print(ans + 1)

Submission status: Wrong Answer

Solution code:
_ = input()
A = map(int, input().split())
prev = next(A)
up = None
count = 1
for i in A:
    if prev < i:
        if up is None:
            up = True
        elif not up:
            count += 1
            up = None
    else:
        if up is None:
            up = False
        elif up:
            count += 1
            up = None
    prev = i
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(N-2):
  if A[i] <= A[i+1]:
    if A[i+1] > A[i+2]:
      count += 1
      break
for i in range(N-2):
  if A[i] >= A[i+1]:
    if A[i+1] < A[i+2]:
      count += 1
      break

print(count + 1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
K=1
R=list()
N=int(input())
L=list(map(int,input().split()))
for i in range(1,N-1):
  if L[i-1]>=L[i] and L[i]<L[i+1] and i-1 not in R:
    K=K+1
    R.append(i)
  elif L[i-1]<=L[i] and L[i]>L[i+1] and i-1 not in R:
    K=K+1
    R.append(i)
print(K)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline

flagset = ['not increase', 'flat', 'not decrease']

def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    cnt = 0
    A0 = A[0]
    flag = flagset[1]
    for i in range(N-1):
        Ai = A[i]
        Ai1 = A[i+1]
        if flag == 'flat':
            if Ai1 == Ai+1:
                flag = 'not decrease'
            elif Ai1 == Ai-1:
                flag = 'not increase'
            elif Ai1 == Ai:
                flag = 'flat'
            else:
                cnt += 1
        elif flag == 'not decrease':
            if Ai1 in [Ai, Ai+1]:
                continue
            else:
                flag = 'flat'
                cnt += 1
        else:
            if Ai1 in [Ai, Ai-1]:
                continue
            else:
                flag = 'flat'
                cnt += 1
    cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

read= sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 1000000007
sys.setrecursionlimit(10**7)

#N,*A = map(int,read().split())
N = int(input())
A = list(map(int,input().split()))

State = 0
res = 1

for i in range(1,N):
    if A[i] > A[i-1]:
        X = 1
    elif A[i] == A[i-1]:
        X = 0
    else :
        X = -1

    if X == State:
        continue
    else:
        if  State == 0:
            State = X
            continue
        else:
            res += 1
            State = 0

print(res)

Submission status: Wrong Answer

Solution code:
import sys

read= sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 1000000007
sys.setrecursionlimit(10**7)

#N,*A = map(int,read().split())
N = int(input())
A = list(map(int,input().split()))

State = 0
res = 1

for i in range(1,N):
    if A[i] > A[i-1]:
        X = 1
    elif A[i] == A[i-1]:
        X = 0
    else :
        X = -1

    if X == State:
        continue

    if  State == 0:
        State = X
        continue

    res += 1
    State = 0

print(res)

Submission status: Wrong Answer

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

ans = 1
sq = 0
a = A[0]
for i in range(1,n):
    print(a,A[i], sq)
    if sq == 0 and A[i] < a:
        sq = -1
    elif sq == 0 and A[i] > a:
        sq = 1
    elif (sq == 1 and A[i] < a) or (sq == -1 and A[i] > a):
        print('---')
        ans += 1
        sq = 0
    a = A[i]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    if len(set(A)) == 1:
        print(1)
        return

    flag = True; increase = True; cnt = 0
    for i in range(N-1):
        now = A[i]
        nxt = A[i+1]
        #end = True
        if flag:
            if nxt == now + 1:
                increase = True
                flag = False
            elif nxt == now - 1:
                increase = False
                flag = False
            elif nxt == now:
                flag = True
                #end = False
            else:
                flag = True
                cnt += 1
        elif increase:
            if not nxt in [now, now + 1]:
                increase = False
                flag = True
                cnt += 1
        else:
            if not nxt in [now, now - 1]:
                increase = True
                flag = True
                cnt += 1
    #if end:
    cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

A.append(A[N-1])
ans = 1
last = A[0]
s = 0
for i in range(N-1):
    if not(A[s] <= A[i] <= A[i+1]) and not(A[s] >= A[i] >= A[i+1]):
        s = i + 1
        ans += 1

print(ans)

Submission status: Wrong Answer

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

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

d = [0] * (n - 1)
if (L[0] > L[1]):
    d[0] = -1
elif (L[0] < L[1]):
    d[0] = 1

cnt = 1
dec_cnt = 0
set_count = 0
for i in range(n):
    if (i == 0):
        continue
    elif (i == n - 1):
        break
    else:
        if (L[i] < L[i + 1] and d[i - 1] >= 0):
            d[i] = 1
        elif (L[i] > L[i + 1] and d[i - 1] <= 0):
            d[i] = -1


prev = 0
count = 0
for i, v in enumerate(d):
    if (i == 0):
        prev = v
        continue
    if (prev == 1):
        if (v == 1):
            continue
        elif (v == 0):
            continue
        else:
            count += 1
            prev = v
    elif (prev == -1):
        if (v == 1):
            continue
        elif (v == 0):
            continue
        else:
            count += 1
            prev = v

print(count + 1)

Submission status: Wrong Answer

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

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

d = [0] * (n - 1)
if (L[0] > L[1]):
    d[0] = -1
elif (L[0] < L[1]):
    d[0] = 1

cnt = 1
dec_cnt = 0
for i in range(n):
    if (i == 0):
        continue
    elif (i == n - 1):
        break
    else:
        if (L[i] < L[i + 1] and d[i - 1] >= 0):
            d[i] = 1
        elif (L[i] > L[i + 1] and d[i - 1] <= 0):
            d[i] = -1
        elif (L[i] < L[i + 1] and d[i - 1] < 0):
            cnt += 1
        elif (L[i] > L[i + 1] and d[i - 1] > 0):
            cnt += 1
        elif (L[i] == L[i + 1] and d[i - 1] > 0):
            cnt += 1
        elif (L[i] == L[i + 1] and d[i - 1] < 0):
            cnt += 1


print(cnt)

Submission status: Wrong Answer

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

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

d = [0] * (n - 1)
if (L[0] > L[1]):
    d[0] = -1
elif (L[0] < L[1]):
    d[0] = 1

cnt = 1
dec_cnt = 0
for i in range(n):
    if (i == 0):
        continue
    elif (i == n - 1):
        break
    else:
        print(d)
        if (L[i] < L[i + 1] and d[i - 1] >= 0):
            d[i] = 1
        elif (L[i] > L[i + 1] and d[i - 1] <= 0):
            d[i] = -1
        elif (L[i] < L[i + 1] and d[i - 1] < 0):
            cnt += 1
        elif (L[i] > L[i + 1] and d[i - 1] > 0):
            cnt += 1
        elif (L[i] == L[i + 1] and d[i - 1] > 0):
            cnt += 1
        elif (L[i] == L[i + 1] and d[i - 1] < 0):
            cnt += 1


print(cnt)

Submission status: Wrong Answer

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

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

d = [0] * (n - 1)
if (L[0] > L[1]):
    d[0] = -1
elif (L[0] < L[1]):
    d[0] = 1

cnt = 1
for i in range(n):
    if (i == 0):
        continue
    elif (i == n - 1):
        break
    else:
        if (L[i] < L[i + 1] and d[i - 1] >= 0):
            d[i] = 1
            if (d[i - 1] == 0):
                cnt += 1
        elif (L[i] > L[i + 1] and d[i - 1] <= 0):
            d[i] = -1
            if (d[i - 1] == 0):
                cnt += 1
        elif (L[i] < L[i + 1] and d[i - 1] < 0):
            cnt += 1
        elif (L[i] > L[i + 1] and d[i - 1] > 0):
            cnt += 1
        elif (L[i] == L[i + 1]):
            continue

print(cnt)

Submission status: Wrong Answer

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

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

d = [0] * (n - 1)
if (L[0] > L[1]):
    d[0] = -1
elif (L[0] < L[1]):
    d[0] = 1

cnt = 1
for i in range(n):
    if (i == 0):
        continue
    elif (i == n - 1):
        break
    else:
        if (L[i] < L[i + 1] and d[i - 1] >= 0):
            d[i] = 1
        elif (L[i] > L[i + 1] and d[i - 1] <= 0):
            d[i] = -1
        elif (L[i] < L[i + 1] and d[i - 1] < 0):
            cnt += 1
        elif (L[i] > L[i + 1] and d[i - 1] > 0):
            cnt += 1
        elif (L[i] == L[i + 1]):
            continue

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    prev='ryouhou'
    cnt=0
    if n==1 or n==2:
        print(1)
    else:
        for i in range(n-1):
            if l[i+1]-l[i]>0:
                if prev=='-':
                    cnt+=1
                    prev='ryouhou'
                else:
                    prev='+'
            elif l[i+1]-l[i]<0:
                if prev=='+':
                    cnt+=1
                    prev='ryouhou'
                else:
                    prev='-'
            else:
                prev='ryouhou'
        print(cnt+1)
resolve()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    prev='ryouhou'
    cnt=0
    if n==1 or n==2:
        print(0)
    else:
        for i in range(n-1):
            if l[i+1]-l[i]>0:
                if prev=='-':
                    cnt+=1
                    prev='ryouhou'
                else:
                    prev='+'
            elif l[i+1]-l[i]<0:
                if prev=='+':
                    cnt+=1
                    prev='ryouhou'
                else:
                    prev='-'
            else:
                prev='ryouhou'
        print(cnt+1)
resolve()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    prev='ryouhou'
    cnt=0
    for i in range(n-1):
        if l[i+1]-l[i]>0:
            if prev=='-':
                cnt+=1
                prev='ryouhou'
            else:
                prev='+'
        elif l[i+1]-l[i]<0:
            if prev=='+':
                cnt+=1
                prev='ryouhou'
            else:
                prev='-'
        else:
            prev='ryouhou'
    print(cnt+1)
resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

prev = A[0]
isUp = True
isDown = True

ans = 0
for a in A[1:]:
  if prev == a:
    pass
  elif prev < a:
    isDown = False
    if not isUp:
      isUp = True
      ans += 1
  elif a < prev:
    isUp = False
    if not isDown:
      isDown = True
      ans += 1
      
  prev = a
  
print(ans+1)

Submission status: Wrong Answer

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

prev = A[0]
isUp = True
isDown = True

ans = 0
for a in A[1:]:
  if prev == a:
    pass
  elif prev < a:
    isDown = False
    if not isUp:
      isUp = True
      ans += 1
  elif a < prev:
    isUp = False
    if not isDown:
      isDown = True
      ans += 1
      
  prev = a
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

read= sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 1000000007
sys.setrecursionlimit(10**7)

N = int(readline())
A = list(map(int,readline().split()))

res = 0

in_i = 0
de_i = 0
i = 0
while i < N-1:
    for j in range(i+1,N):
        if A[j] >= A[j-1]:continue
        else:
            break

    in_i = j
    for j in range(i+1,N):
        if A[j] <= A[j-1]:continue
        else:
            break
    de_i = j

    i = max(de_i,in_i)
    res+=1
#print(res)

if len(A) > 2:
    if (A[-3] - A[-2])*(A[-2] - A[-1]) >= 0: print(res)
    else: print(res+1)
else:
    print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int, input().split()))
cnt = 1
state = None
i = 1
while i < n:
    if state is None:
        if L[i] > L[i - 1]:
            state = 'up'
        elif L[i] < L[i - 1]:
            state = 'down'
        i += 1
    else:
        if state == 'up':
            while L[i] >= L[i - 1] and i < n - 1:
                i += 1
            cnt += 1
            i += 1
            state = None
        else:
            while L[i] <= L[i - 1] and i < n - 1:
                i += 1
            cnt += 1
            i += 1
            state = None
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int, input().split()))
cnt = 1
L2 = [''] * (n - 1)
for i in range(n - 1):
    L2[i] = L[i + 1] - L[i]
j = 0
flag = 1
for j in range(n - 1):
    if flag == 1:
        prev = L2[j]
        flag = 0
    else:
        if L2[j] * prev < 0:
            prev = L2[j]
            cnt += 1
            flag = 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int, input().split()))
cnt = 1
L2 = [''] * (n - 1)
for i in range(n - 1):
    L2[i] = L[i + 1] - L[i]
j = 0
while j < n - 2:
    if L2[j + 1] * L2[j] < 0:
        cnt += 1
        j += 1
    j += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if(N == 1):
    print(1)
    exit(0)
cur = A[0]
# 昇順(1)か降順(0)かのフラグ
ans = 1
flag = -1
for i in range(1, N):
    if(cur == A[i]): continue
    if(flag == -1):
        if(A[i] > cur): flag = 1
        elif(A[i] < cur): flag = 0
        cur = A[i]
        continue
    if(flag == 1 and A[i] < cur):
        cur, flag = A[i], -1
        ans += 1
        continue
    if(flag == 1 and A[i] > cur):
        cur = A[i]
        continue
    if(flag == 0 and A[i] > cur):
        cur, flag = A[i], -1
        ans += 1
        continue
    if(flag == 0 and A[i] < cur):
        cur == A[i]
        continue
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if(N == 1):
    print(1)
    exit(0)
cur = A[0]
# 昇順(1)か降順(0)かのフラグ
ans = 1
flag = -1
for i in range(1, N):
    if(cur == A[i]): continue
    if(flag == -1):
        if(A[i] > cur): flag = 1
        else: flag = 0
        cur = A[i]
        continue
    if(flag == 1 and A[i] < cur):
        cur, flag = A[i], -1
        ans += 1
        continue
    if(flag == 1 and A[i] > cur):
        cur = A[i]
        continue
    if(flag == 0 and A[i] > cur):
        cur, flag = A[i], -1
        ans += 1
        continue
    if(flag == 0 and A[i] < cur):
        cur == A[i]
        continue
print(ans)

Submission status: Wrong Answer

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

count = 1
state = ""
for i in range(N-1):
    if A[i] >= A[i+1] and state == "":
        state = "minus"
    elif A[i] >= A[i+1] and state == "plus":
        state = ""
        count += 1
    elif A[i] >= A[i+1] and state == "minus":
        continue
    elif A[i] <= A[i+1] and state == "":
        state = "plus"
    elif A[i] <= A[i+1] and state == "minus":
        state = ""
        count += 1
    else:
        continue

print(count)

Submission status: Wrong Answer

Solution code:
# A - Sorted Arrays
import numpy as np

N = int(input())
A = list(map(int, input().split()))
sgn = 0
ans = 1

for i in range(N-1):
    tmp = np.sign(A[i+1]-A[i])
    if tmp*sgn<0:
        ans += 1
    sgn = np.sign(2*sgn+tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
# A - Sorted Arrays
import numpy as np

N = int(input())
A = list(map(int, input().split()))
sgn = 0
ans = 1

for i in range(N-1):
    tmp = np.sign(A[i+1]-A[i])
    if tmp*sgn<0:
        ans += 1
    sgn = tmp

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))

# ===CODE===
tMOD = 998244353


def main():
    n = ni()
    a = na()

    if n == 1:
        print(0)
        exit(0)

    tmp = []
    state = 0
    ans = 0
    for i in range(n):
        if len(tmp) < 1:
            hoge=0
        else:
            current_state = a[i]-tmp[-1]
            if current_state == 0:
                hoge=0
            elif state == 0:
                if current_state > 0:
                    state = 1
                else:
                    state = -1
            elif state * current_state < 0:
                tmp.clear()
                ans += 1
                state=0
        tmp.append(a[i])

    print(ans+1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
zougen = 4 #0は変化無し、1は減少、２は増加、4は未決定
ans=1
for i in range(N-1):
    if zougen==4:
        if A[i]-A[i+1]<0:
            zougen = 2
        elif A[i]-A[i+1]>0:
            zougen = 1
        else:
            zougen =0
    if A[i]-A[i+1]<0:
        if zougen == 1:
            ans+=1
            zougen=4
    if A[i]-A[i+1]>0:
        if zougen == 2:
            ans+=1
            zougen=4
print(ans)

Submission status: Wrong Answer

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

Ad = [A[i] - A[i+1] for i in range(N-1)]

ans = 1
p = 0
for d in Ad:
    if d * p < 0:
        ans += 1
        p = 0
    else:
        p = d

print(ans)

Submission status: Wrong Answer

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

cnt = 1
inc = False
dec = False
p = A.pop(0)

for Ai in A:
    if (not inc) and (not dec):
        if Ai < p:
            dec = True
        else:
            inc = True
    elif inc:
        if Ai < p:
            cnt += 1
            inc = False
    elif dec:
        if Ai > p:
            cnt += 1
            dec = False
    p = Ai
    
print(cnt)

Submission status: Wrong Answer

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

cnt1 = 1
r = True
p = A[0]
for i in range(1, N):
    if r and p < A[i]:
        r = False
        cnt1 += 1
    elif not r and p > A[i]:
        r = True
        cnt1 += 1
    p = A[i]
    
cnt2 = 1
r = False
p = A[0]
for i in range(1, N):
    if r and p < A[i]:
        r = False
        cnt2 += 1
    elif not r and p > A[i]:
        r = True
        cnt2 += 1
    p = A[i]
    
print(min(cnt1, cnt2))

Submission status: Wrong Answer

Solution code:
# 2020/05/07
# AtCoder Grand Contest 013 - A

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

# Calc
cnt = 1
dr = 0
sav = a[0]
for i in range(1, n):
    # Initial Status
    if dr == 0:
        # Increase
        if sav < a[i]:
            dr = 1
        # Decrease
        elif sav > a[i]:
            dr = -1
    # Case Increase
    elif dr == 1:
        if sav > a[i]:
            cnt = cnt + 1
            dr = -1
    # Case Decrease
    elif dr == -1:
        if sav < a[i]:
            cnt = cnt + 1
            dr = 0
    sav = a[i]

ans = cnt

# Output
print(ans)

Submission status: Wrong Answer

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

ans = 1
i = 0

ls = [0]*(N-1)
for i in range(N-1):
  if A[i] > A[i+1]:
    ls[i] = 1
  elif A[i] < A[i+1]:
    ls[i] = -1
  else:
    if i == 0:
      ls[i] = 0
    else:
      ls[i] = ls[i-1]

j = 0
while j < N-2:
  if ls[j] == 1:
    if ls[j+1] == -1:
      ans += 1
      j += 1
  elif ls[j] == -1:
    if ls[j+1] == 1:
      ans += 1
      j += 1
  j += 1
print(ans)

Submission status: Wrong Answer

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

ans = 1
i = 0

ls = [0]*(N-1)
for i in range(N-1):
  if A[i] > A[i+1]:
    ls[i] = 1
  elif A[i] < A[i+1]:
    ls[i] = -1
  else:
    if i == 0:
      ls[i] = 0
    else:
      ls[i] = ls[i-1]

print(ls)

j = 0
while j < N-2:
  if ls[j] == 1:
    if ls[j+1] == -1:
      ans += 1
      j += 1
  elif ls[j] == -1:
    if ls[j+1] == 1:
      ans += 1
      j += 1
  j += 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] < A[i+1]:
    if A[i+1] > A[i+2]:
      ans += 1
      i += 1
  elif A[i] > A[i+1]:
    if A[i+1] < A[i+2]:
      ans += 1
      i += 1
  i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
trend = [0] * (N - 1)
for i in range(N - 1):
    trend[i] = A[i + 1] - A[i]
    if trend[i] != 0:
        trend[i] //= abs(trend[i])
ans = 1
i = 0
while i < N - 2:
    if trend[i + 1] * trend[i] not in (0, 1):
        ans += 1
        i += 2
    else:
        i += 1
print(ans)

Submission status: Wrong Answer

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

flag = 0
cnt_length = 0
ans = 0

i = 0
while i < N-1:
    if i == N-2:
        if (A[i+1] - A[i] > 0 and flag == 1) or cnt_length == 1:
            ans += 1
        elif (A[i+1] - A[i] < 0 and flag == -1) or cnt_length == 1:
            ans += 1

    cnt_length += 1

    if A[i+1] - A[i] > 0:
        if flag == 0:
            flag = 1

        if flag == -1 and cnt_length != 1:
            ans += 1
            flag = 1
            cnt_length = 0
        elif flag == -1:
            flag = 1
    elif A[i+1] - A[i] < 0:
        if flag == 0:
            flag = -1

        if flag == 1 and cnt_length != 1:
            ans += 1
            flag = -1
            cnt_length = 0
        elif flag == 1:
            flag = -1
    i += 1

print(ans)

Submission status: Wrong Answer

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

flag = 0
cnt_length = 0
ans = 0

i = 0
while i < N-1:
    if i == N-2:
        print(flag)
        if (A[i+1] - A[i] > 0 and flag == 1) or cnt_length == 1:
            ans += 1
        elif (A[i+1] - A[i] < 0 and flag == -1) or cnt_length == 1:
            ans += 1

    cnt_length += 1

    if A[i+1] - A[i] > 0:
        if flag == 0:
            flag = 1

        if flag == -1 and cnt_length != 1:
            ans += 1
            flag = 1
            cnt_length = 0
        elif flag == -1:
            flag = 1
    elif A[i+1] - A[i] < 0:
        if flag == 0:
            flag = -1

        if flag == 1 and cnt_length != 1:
            ans += 1
            flag = -1
            cnt_length = 0
        elif flag == 1:
            flag = -1
    i += 1

print(ans)