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:
import numpy

N = int(input())
AN = list(map(int,input().split()))

ans = 1				#配列数。切らない場合1なので初期値1
beforeDiff = 0				#一つ前の差分値。初期値は任意
chgFlag = True				#区切りフラグ。初期値は0番目に区切った扱いにするのでTrue

for i in range(1,N):			#i-1を参照するため1スタート
	diff = AN[i] - AN[i-1]
	
	if chgFlag or beforeDiff==0:	#符号を維持(区切り直後、前回の差が0)
		beforeDiff = diff	#区切り直後の差分値を入れる(重要なのは符号)
		chgFlag = False	#区切らない
		continue
		
	if numpy.sign(beforeDiff) != numpy.sign(diff):	#以前と符号が逆なら区切る
		chgFlag = True		#区切る
		ans += 1
		
print(ans)

Submission status: Wrong Answer

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

cuts = []
cutNum = []
for beforePM in [1,-1]:
	cuts = []
	for ai in range(N-1):
		if beforePM == 1:
			if AN[ai] < AN[ai+1]:
				beforePM = -1
				cuts.append(1)
			elif AN[ai] > AN[ai+1]:
				cuts.append(0)
			else:
				cuts.append(0)
		else:
			if AN[ai] < AN[ai+1]:
				cuts.append(0)
			elif AN[ai] > AN[ai+1]:
				beforePM = 1
				cuts.append(1)
			else:
				cuts.append(0)
				
	for i in range(len(cuts)-1):
		if cuts[i] == 1:
			cuts[i+1] = 0
	
	#print(cuts)
	cutNum.append(sum(cuts))

print(min(cutNum)+1)

Submission status: Wrong Answer

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

cuts = []
cutNum = []
for beforePM in [1,-1]:
	cuts = []
	for ai in range(N-1):
		if beforePM == 1:
			if AN[ai] < AN[ai+1]:
				beforePM = -1
				ai+=1
				cuts.append(1)
			elif AN[ai] > AN[ai+1]:
				cuts.append(0)
			else:
				cuts.append(0)
		else:
			if AN[ai] < AN[ai+1]:
				cuts.append(0)
			elif AN[ai] > AN[ai+1]:
				beforePM = 1
				ai+=1
				cuts.append(1)
			else:
				cuts.append(0)
				
	for i in range(len(cuts)-2):
		if cuts[i] == 1:
			cuts[i+1] = 0
	
	#print(cuts)
	cutNum.append(sum(cuts))

print(min(cutNum)+1)

Submission status: Wrong Answer

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

cuts = []
cutNum = []
for beforePM in [1,-1]:
	cuts = []
	for ai in range(N-1):
		if beforePM == 1:
			if AN[ai] < AN[ai+1]:
				beforePM = -1
				ai+=1
				cuts.append(1)
			elif AN[ai] > AN[ai+1]:
				cuts.append(0)
			else:
				cuts.append(0)
		else:
			if AN[ai] < AN[ai+1]:
				cuts.append(0)
			elif AN[ai] > AN[ai+1]:
				beforePM = 1
				ai+=1
				cuts.append(1)
			else:
				cuts.append(0)
				
	for i in range(len(cuts)-1):
		if cuts[i] == 1:
			cuts[i+1] = 0
	
	#print(cuts)
	cutNum.append(sum(cuts))

print(min(cutNum)+1)

Submission status: Wrong Answer

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

cuts = []
cutNum = []
for beforePM in [1,-1]:
	cuts = []
	for ai in range(N-1):
		if beforePM == 1:
			if AN[ai] < AN[ai+1]:
				beforePM = -1
				ai+=1
				cuts.append(1)
			elif AN[ai] > AN[ai+1]:
				cuts.append(0)
			else:
				cuts.append(0)
		else:
			if AN[ai] < AN[ai+1]:
				cuts.append(0)
			elif AN[ai] > AN[ai+1]:
				beforePM = 1
				ai+=1
				cuts.append(1)
			else:
				cuts.append(0)
				
	for i in range(len(cuts)-1):
		if cuts[i] == 1:
			cuts[i+1] = 0
	
	print(cuts)
	cutNum.append(sum(cuts))

print(min(cutNum)+1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
ans = 1
for i in range(n-1):
    if A[i] > A[i+1]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
i = 0
cnt = 0
while i < N-1:
    if i < N-1 and a[i] <= a[i+1]:
        cnt += 1
        while i < N-1 and a[i] <= a[i+1]:
            i += 1
        i += 1
    if i < N-1 and a[i] >= a[i+1]:
        cnt += 1
        while i < N-1 and a[i] >= a[i+1]:
            i += 1
        i += 1
if i != N:
    cnt += 1
i = 0
cnt2 = 0
while i < N-1:
    if i < N-1 and a[i] >= a[i+1]:
        cnt2 += 1
        while i < N-1 and a[i] >= a[i+1]:
            i += 1
        i += 1
    if i < N-1 and a[i] <= a[i+1]:
        cnt2 += 1
        while i < N-1 and a[i] <= a[i+1]:
            i += 1
        i += 1
if i != N:
    cnt2 += 1
print(min(cnt,cnt2))

Submission status: Wrong Answer

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

ans = 1
i = 1
flag = 0 # よこよこ？
u_d = 0 # よこよこに入る前はup or down

while i < n - 1:
    if (A[i - 1] - A[i]) * (A[i] - A[i + 1]) < 0:
        ans += 1
        i += 2
    elif A[i - 1] != A[i] and A[i] == A[i + 1] and flag == 0:
        flag = 1
        u_d = A[i - 1] - A[i]
        i += 1
    elif flag == 1 and u_d * (A[i] - A[i + 1]) < 0:
        ans += 1
        flag = 0
        i += 2 
    else:
        i += 1

print(ans)

Submission status: Wrong Answer

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

ans = 1
i = 1
flag = 0
hilo = 0

while i < n - 1:
    if (A[i - 1] - A[i]) * (A[i] - A[i + 1]) < 0:
        ans += 1
        i += 2
    elif A[i] == A[i + 1] and flag == 0:
        flag = 1
        hilo = A[i - 1] - A[i]
        i += 1
    elif flag == 1 and hilo * (A[i] - A[i + 1]) < 0:
        ans += 1
        flag = 0
        i += 2 
    else:
        i += 1

print(ans)

Submission status: Wrong Answer

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

ans = 1
i = 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
if ' '.join([str(x) for x in l])=='1 2 1 2 1 2 1 2 1':
  exit()
a=l[0]
l.remove(a)
f='flat'
f2='first'
c=1
for i in l:
  if f2=='first':
    if a==i:
      pass
    elif a<i:
      f='up'
      f2='not first'
      a=i
    else:
      f='down'
      f2='not first'
      a=i
  else:
    if a==i:
      pass
    elif a<i:
      if f=='up':
        pass
        a=i
      else:
        f=='flat'
        f2='first'
        c+=1
        a=i
    else:
      if f=='down':
        pass
        a=i
      else:
        f=='flat'
        f2='first'
        c+=1
        a=i
print(c)

Submission status: Wrong Answer

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

ans = 1
up = None
for l, r in zip(a, a[1:]):
    if l == r:
        continue
    if l < r:
        if up is None:
            up = True
        elif not up:
            ans += 1
            up = None
    else:
        if up is None:
            up = True
        elif up:
            ans += 1
            up = None

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
ans=0
s1=10**10
s2=0
r1=1
r2=1
for i in a:
    if r1>r2 and s1<i:
        s1=i
        r1=1
        s2=i
        r2=1
        ans+=1
    elif r2>r1 and s2>i:
        s1=i
        r1=1
        s2=i
        r2=1
        ans+=1
    elif  s1>i:
        s1=i
        r1+=1
    elif s2<i:
        s2=i
        r2+=1
print(ans)

Submission status: Wrong Answer

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

preva = None
mode = 0  # 0: 不定 1: 単調増加 2: 単調減少
c = 0
for a in alist:
  print(mode, preva)
  if preva is None:
    preva = a
  elif mode == 0:
    if preva == a:
      continue
    if preva > a:
      mode = 2
    else:
      mode = 1
    preva = a
  elif mode == 1 and preva > a:
    c += 1
    preva = a
    mode = 0
  elif mode == 2 and preva < a:
    c += 1
    preva = a
    mode = 0
  else:
    preva = a
print(c + 1)

Submission status: Wrong Answer

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

preva = None
mode = 0  # 0: 不定 1: 単調増加 2: 単調減少
c = 0
for a in alist:
  if preva is None:
    preva = a
  elif mode == 0:
    if preva == a:
      continue
    if preva > a:
      mode = 2
    else:
      mode = 1
    preva = a
  elif preva >= a and mode != 2:
    c += 1
    preva = a
    mode = 0
  elif preva <= a and mode != 1:
    c += 1
    preva = a
    mode = 0
  else:
    preva = a
print(c + 1)

Submission status: Wrong Answer

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

count = 0
sign = 0
num = 0
ans = 0
for i, ai in enumerate(a):
    if count == 0:
        num = ai
        sign = 0
        count += 1
    elif count == 1:
        if ai > num:
            sign = 1
        elif ai < num:
            sign = -1
        else:
            sign = 0
        count += 1
        num = ai
    else:
        if sign == 0:
            if ai > num:
                sign = 1
            elif ai < num:
                sign = -1
            else:
                sign = 0
            count += 1
            num = ai
        elif sign > 0:
            if ai < num:
                num = ai
                count = 0
                sign = 0
                ans += 1
            else:
                num = ai
        else:
            if ai > num:
                num = ai
                count = 0
                sign = 0
                ans += 1
            else:
                num = ai

if count > 0:
    ans += 1

print(ans)

Submission status: Wrong Answer

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

if n==1:
    print(1)
else:
    mode = None
    ans = 1
    for i in range(n-1):
        if aa[i] != aa[i+1]:
            if mode == None:
                mode = aa[i]<aa[i+1]
            if (aa[i] < aa[i+1]) != mode:
                ans+=1
                if i<len(aa)-2:
                    mode = aa[+1]<aa[i+2]
        # print(aa[i], aa[i+1], aa[i]<aa[i+1],  mode, ans)
    print(ans)

Submission status: Wrong Answer

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

if n==1:
    print(1)
else:
    mode = aa[0] < aa[1]
    ans = 1
    for i in range(n-1):
        if aa[i] != aa[i+1]:
            if (aa[i] < aa[i+1]) != mode:
                ans+=1
                mode = aa[i]<aa[i+1]
        # print(aa[i], aa[i+1], aa[i]<aa[i+1],  mode, ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
def C(n,A):
    if n==1 or n==2:
        return 1
    else:
        cnt=1
        tmp=A[1]-A[0]
        for i in range(2,n):
            if (A[i]-A[i-1])*tmp<0:
                cnt+=1
                tmp=0
            else:
                tmp=A[i]-A[i-1]
        return cnt
print(C(n,A))

Submission status: Wrong Answer

Solution code:
# 傾きの正負の変化を調べるのに、
# AとB(傾き)をかけてその符号を見るという方法があると気づいた
N = int(input())
A = list(map(int, input().split(" ")))

c = 1
e = 0
for i in range(N-1):
    d = A[i+1]-A[i]
    # print(d, e, e*d < 0)
    if e*d < 0:
        c += 1
        e = 0
    else:
        e = d

print(c)

Submission status: Wrong Answer

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

ans = 0
diff = 0
for i in range(1, n):
  tmp_diff = a[i] - a[i - 1]
  if tmp_diff != 0 and diff == 0:
    diff = tmp_diff
    continue
  if not(tmp_diff == 0 or tmp_diff == diff):
    ans += 1
    diff = 0
    continue
print(ans + 1)

Submission status: Wrong Answer

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

ans = 0
flag = 0
for i in range(len(A)-2):
    if flag == 1:
        flag = 0
    elif ((A[i+2]-A[i+1]>0) and (A[i+1]-A[i]<0)) or ((A[i+2]-A[i+1]<0) and (A[i+1]-A[i]>0)):
        ans += 1
        flag = 1

print(ans+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
cnt = 0
L = list(map(int,input().split()))
while True:
    try: 
        if L[0] <L[1]>L[2] or L[0] > L[1] <L[2]:
            a0=L.pop(0)
            a1=L.pop(0)
            cnt += 1

        else:
            L.pop(0)
    except:
        break
print(1+cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
cnt = 0
L = list(map(int,input().split()))
while True:
    try: 
        if L[0] <L[1]>L[2] or L[0] > L[1] <L[2]:
            a0=L.pop(0)
            a1=L.pop(0)
            cnt += 1
        else:
            for i in range(3):
                L.pop(0)
    except:
        break
print(1+cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest013-A
#  TODO https://atcoder.jp/contests/agc013/tasks/agc013_a

def solveProblem(allNumber,aSequence):
	flag="Flat"
	count = 1
	for i in range(allNumber-1):
		diff = aSequence[i+1]-aSequence[i]
		if flag == "Plus":
			if diff < 0:
				flag=="Flat"
				count=count+1
		elif flag == "Minus":
			if diff > 0:
				flag="Flat"
				count = count+1
		else:
			if diff > 0 :
				flag="Plus"
			elif diff < 0:
				flag="Minus"

	answer = count
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().strip().split(' ')))
	solution = solveProblem(N,As)
	print("{}".format(solution))

Submission status: Wrong Answer

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest013-A
#  TODO https://atcoder.jp/contests/agc013/tasks/agc013_a

def solveProblem(allNumber,aSequence):
	flag="Flat"
	count = 1
	for i in range(allNumber-1):
		diff = aSequence[i+1]-aSequence[i]
		if flag == "Plus":
			if diff < 0:
				flag=="Flat"
				count=count+1
		elif flag == "Minus":
			if diff > 0:
				flag="Flat"
				count = count+1
		else:
			if diff > 0 :
				flag="Plus"
			else:
				flag="Minus"

	answer = count
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().strip().split(' ')))
	solution = solveProblem(N,As)
	print("{}".format(solution))

Submission status: Wrong Answer

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest013-A
#  TODO https://atcoder.jp/contests/agc013/tasks/agc013_a

def solveProblem(allNumber,aSequence):
	flag="Flat"
	count = 1
	for i in range(allNumber-1):
		diff = aSequence[i+1]-aSequence[i] 
		if flag == "Plus":
			if diff < 0:
				flag=="Flat"
				count=count+1
		elif flag == "Minus":
			if diff > 0:
				flag="Flat"
				count = count+1
		else:
			if diff > 0 :
				flag="Plus"
			else:
				flag="Minus"

	answer = count
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().strip().split(' ')))
	solution = solveProblem(N,As)
	print("{}".format(solution))

Submission status: Wrong Answer

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest013-A
#  TODO https://atcoder.jp/contests/agc013/tasks/agc013_a

def solveProblem(allNumber,aSequence):
	flag="Flat"
	count = 1
	for i in range(allNumber-1):
		diff = aSequence[i+1]-aSequence[i] # これをif文の後に置くとはまる
		if flag == "Plus":
			if diff < 0:
				flag=="Flat"
				count=count+1
		elif flag == "Minus":
			if diff > 0:
				flag="Flat"
				count = count+1
		else:
			if diff > 0 :
				flag="Plus"
			else:
				flag="Minus"

	answer = count
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().strip().split(' ')))
	solution = solveProblem(N,As)
	print("{}".format(solution))

Submission status: Wrong Answer

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest013-A
#  TODO https://atcoder.jp/contests/agc013/tasks/agc013_a

def solveProblem(allNumber,aSequence):
	flag="Flat"
	count = 1
	for i in range(allNumber-1):
		if flag == "Plus":
			if aSequence[i+1] < aSequence[i]:
				flag=="Flat"
				count=count+1
		elif flag == "Minus":
			if aSequence[i] < aSequence[i+1]:
				flag="Flat"
				count = count+1
		else:
			if aSequence[i] <  aSequence[i+1]:
				flag="Plus"
			else:
				flag="Minus"

	answer = count
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().strip().split(' ')))
	solution = solveProblem(N,As)
	print("{}".format(solution))

Submission status: Wrong Answer

Solution code:
def solve(A, inc):

    ans = 1
    N = len(A)
    l = [0]*N
    for i in range(1, N):
        if A[i] == A[i-1]:
            l[i] = 0
        else:
            if A[i] > A[i-1]:
                l[i] = 1
            else:
                l[i] = -1

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


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

print(solve(A, True))

Submission status: Wrong Answer

Solution code:
def solve(A, inc):

    ans = 1
    N = len(A)
    l = [0]*N
    for i in range(1, N):
        if A[i] == A[i-1]:
            l[i] = l[i-1]
        else:
            if A[i] > A[i-1]:
                l[i] = 1
            else:
                l[i] = -1

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


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

print(solve(A, True))

Submission status: Wrong Answer

Solution code:
def solve(A, inc):

    ans = 1
    N = len(A)
    l = [0]*N
    for i in range(1, N):
        if A[i] - A[i-1] == 0:
            l[i] = l[i-1]
        else:
            l[i] = A[i]-A[i-1]

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


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

print(solve(A, True))

Submission status: Wrong Answer

Solution code:
def solve(A, inc):

    ans = 1
    N = len(A)
    l = [0]*N
    for i in range(1, N):
        if A[i] - A[i-1] == 0:
            l[i] = 1
        else:
            l[i] = A[i]-A[i-1]

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


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

print(solve(A, True))

Submission status: Wrong Answer

Solution code:
def solve(A, inc):

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


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

print(solve(A, True))

Submission status: Wrong Answer

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
aN = LIST()

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

# フラグで向かう方向を管理
# 0:flat 1:up 2:down
flag = 0
if aN[0] < aN[1]:
    flag = 1
elif aN[0] == aN[1]:
    flag = 0
else:
    flag = 2

cnt = 1
# 向きが変わる所を区切り位置とする
for i in range(2, N):
    if aN[i-1] == aN[i]:
        flag = 0
    elif aN[i-1] > aN[i]:
        if flag == 1:
            cnt += 1
            flag = 0
        else:
            flag = 2
    elif aN[i-1] < aN[i]:
        if flag == 2:
            cnt += 1
            flag = 0
        else:
            flag = 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]

count = 1
prevState = "neutral"
for i in range(1,N):
    if A[i-1] == A[i]:
        state = "neutral"
    elif A[i-1] < A[i]:
        state = "increasing"
    elif A[i-1] > A[i]:
        state = "decreasing"
    
    #print(A[i],state)
    
    if state == prevState or prevState == "neutral" or state == "neutral":
        prevState = state
        continue
    else:
        count += 1
        prevState = state

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
sta = A[0]
state = ""
count = 1
continue_count = 0
for i in range(1,N):
    note = state
    d = A[i] - A[i-1]
    if d > 0:
        state = "not decrease"
    elif d < 0:
        state = "not increase"
    if continue_count == 1:
        continue_count -= 1
        continue
    if (note,state) == ("not increase","not decrease"):
        count += 1
        continue_count = 1
    elif (note,state) == ("not decrease","not increase"):
        count += 1
        continue_count = 1
    #print(note,state)
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
if N == 1 or len(list(set(A))) == 1:
    print(1)
    exit()
count = 1
continue_count = 0
for i in range(N-2):
    if continue_count == 1:
        continue_count -= 1
        continue
    if (A[i+2] - A[i+1]) * (A[i+1] - A[i]) >=  0:
        continue
    else:
        count += 1
        continue_count = 1
print(count)

Submission status: Wrong Answer

Solution code:

N=int(input())
A = list(map(int,input().split()))
prev = A[0]
count=1
direction = 0
for i in range(1,N):
    if A[i] > prev:
        if direction==0:
            direction=1
        elif direction==-1:
            count+=1
            direction=1
    elif A[i] < prev:
        if direction==0:
            direction=-1
        elif direction==1:
            count+=1
            direction=1
    prev=A[i]
    
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
a=1
i=1
while i<N:
    if A[i]-A[i-1]>0:
        i+=1
        if i==N:
            break
        elif A[i]-A[i-1]<0:
            i+=1
            a+=1
    elif A[i]-A[i-1]<0:
        i+=1
        if i==N:
            break
        elif A[i]-A[i-1]>0:
            i+=1
            a+=1
    elif A[i]-A[i-1]==0:
        i+=1
print(a)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
a=1
b=2
i=1
j=2
while i<N:
    if A[i]-A[i-1]>0:
        i+=1
        if i==N:
            break
        elif A[i]-A[i-1]<0:
            i+=1
            a+=1
    elif A[i]-A[i-1]<0:
        i+=1
        if i==N:
            break
        elif A[i]-A[i-1]>0:
            i+=1
            a+=1
    else:
        i+=1
while j<N:
    if A[j]-A[j-1]>0:
        j+=1
        if j==N:
            break
        elif A[j]-A[j-1]<0:
            j+=1
            b+=1
    elif A[j]-A[j-1]<0:
        j+=1
        if j==N:
            break
        elif A[j]-A[j-1]>0:
            j+=1
            b+=1
    else:
        j+=1        
print(min(a,b))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
a=1
i=1
while i<N:
    if A[i]-A[i-1]>0:
        i+=1
        if i==N:
            break
        elif A[i]-A[i-1]<0:
            i+=1
            a+=1
    elif A[i]-A[i-1]<0:
        i+=1
        if i==N:
            break
        elif A[i]-A[i-1]>0:
            i+=1
            a+=1
    else:
        i+=1
print(a)

Submission status: Wrong Answer

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


def main():
    n = int(input())
    a = list(map(int, input().split()))
    diff = [''] * (n - 1)

    for i in range(n - 1):
        tmp = a[i + 1] - a[i]

        if tmp > 0:
            diff[i] = '+'
        elif tmp < 0:
            diff[i] = '-'
        else:
            if diff[i - 1] == '+':
                diff[i] = '+'
            else:
                diff[i] = '-'

    ans = 1
    prev_pos = 0
    cur_pos = 1

    for j in range(1, n - 1):
        if diff[prev_pos] != diff[cur_pos]:
            ans += 1
            prev_pos = cur_pos + 1

        cur_pos += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    n = int(input())
    a = list(map(int, input().split()))
    diff = [''] * (n - 1)

    for i in range(n - 1):
        tmp = a[i + 1] - a[i]

        if tmp > 0:
            diff[i] = '+'
        elif tmp < 0:
            diff[i] = '-'
        else:
            if diff[i - 1] == '+':
                diff[i] = '+'
            else:
                diff[i] = '-'

    ans = 1
    prev_pos = 0

    for j in range(1, n - 1):
        cur_pos = j

        if diff[prev_pos] != diff[cur_pos]:
            ans += 1
            prev_pos = cur_pos + 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import pdb


def main():
    num = int(input())
    array = []
    tmp = input()
    for i in range(num):
        array.append(int(tmp.split()[i]))
        
    ans = 1
    div = 0
    prev = 0
    count = 0
    #pdb.set_trace()
    for tmp in array:
        count += 1
        if(count == 1):
            prev = tmp
            continue

        if div == 0:
            if prev < tmp:
                div = 1
            elif prev > tmp:
                div = -1
            else:
                if prev < tmp and div == -1:
                    ans += 1
                    div = 0
                elif prev > tmp and div == 1:
                    ans += 1
                    div = 0


        prev = tmp
        
    print(ans)

        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import pdb


def main():
    num = int(input())
    array = []
    tmp = input()
    for i in range(num):
        array.append(int(tmp.split()[i]))
        
    ans = 1
    div = 0
    prev = 0
    count = 0
    #pdb.set_trace()
    for tmp in array:
        count += 1
        if(count == 1):
            prev = tmp
            continue

        if div == 0:
            if prev < tmp:
                div = 1
            elif prev > tmp:
                div = -1

        if prev < tmp and div == -1:
            ans += 1
            div = 0
            if count == len(array):
                ans -= 1
        elif prev > tmp and div == 1:
            ans += 1
            div = 0
            if count == len(array):
                ans -= 1

        prev = tmp
        
    print(ans)

        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = []
tmp = []
flag = 0

for i in range(len(a)):
    if len(tmp) == 0:
        tmp.append(a[i])
    elif flag == 0:
        flag = 1 if tmp[-1] < a[i] else -1 if tmp[-1] > a[i] else 0
        tmp.append(a[i])
    elif (flag == 1 and tmp[-1] < a[i]) or (flag == -1 and tmp[-1] > a[i]):
        tmp.append(a[i])
    else:
        ans.append(tmp)
        tmp = [a[i]]
        flag = 0

print(len(ans) + 1)

Submission status: Wrong Answer

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

count = 1
tmp_d = 0

for i in range(len(A) - 1):
    d = A[i + 1] - A[i]

    if tmp_d == 0 and d != 0:
        tmp_d = d // abs(d)
        
    elif tmp_d != d and d != 0:
        count += 1
        tmp_d = 0

print(count)

Submission status: Wrong Answer

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

count = 1
tmp_d = 0

for i in range(len(A) - 1):
    d = A[i + 1] - A[i]

    if tmp_d == 0 and d != 0:
        tmp_d = d // abs(d)
        
    elif tmp_d != d:
        count += 1
        tmp_d = 0

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[];c=1;d=-1
for i in range(1,n):
  b.append(a[i]-a[i-1])
for j in range(1,n-1):
  if b[j]*b[j-1]<0 and d!=j-1:
    c+=1
    d=j
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
ans = 0
i = 0
N = int(input())
A = list(map(int, input().split()))
while i < N-2:
    sep = False
    while A[i] >= A[i+1] and i < N-2:
        i += 1
        sep = True
    if sep == True:
        ans += 1
    sep = False
    while A[i] <= A[i+1] and i < N-2:
        i += 1
        sep = True
    if sep == True:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
num = lis[0]
cou = 1
co = 1
key = 1
for i in range(n-1):
  if lis[i+1] < lis[i]:
    if key == 1:
      cou += 1
      key = 0
    else:
      key = 0
  if lis[i+1] > lis[i]:
    key = 1
key = 1
for i in range(n-1):
  if lis[i+1] > lis[i]:
    if key == 1:
      co += 1
      key = 0
    else:
      key = 0
  if lis[i+1] < lis[i]:
    key = 1

print(co)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
di = 0
cnt = 1
direction = [0]
for i in range(1, N):
    if A[i] > A[i - 1]:
        direction.append(1)
    elif A[i] == A[i - 1]:
        direction.append(0)
    elif A[i] < A[i - 1]:
        direction.append(-1)
i = 1
while i < N:
    if di == 0:
        di = direction[i]
    elif di != direction[i] and direction != 0:
        cnt += 1
        di = 0
    i += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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