SMBC 编程竞赛 #2(第 481 场 AtCoder Beginner Contest)
B
折线
Polyline
AtCoder
⌀ 0
原题
← AC →

折线AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

There are $N$ points on the $xy$-plane, numbered $1,2,\ldots,N$. The coordinates of point $i$ are $(i,A_i)$.

在 $xy$ 平面上有 $N$ 个点,编号为 $1,2,\ldots,N$。点 $i$ 的坐标为 $(i,A_i)$。AI (CI翻译)

For $i=1,2,\ldots,N-1$, connect point $i$ and point $i+1$ with a line segment to form one polyline.

对于 $i=1,2,\ldots,N-1$,用一条线段连接点 $i$ 和点 $i+1$,形成一条折线。AI (CI翻译)

Find the number of points on this polyline (including its endpoints) whose $y$-coordinate is $K$.

求这条折线上(包括端点)$y$ 坐标为 $K$ 的点的个数。AI (CI翻译)

Here, the constraints guarantee that the number of points satisfying the condition is finite.

约束条件保证满足条件的点的个数是有限的。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $2 \le N \le 100$
  • $1 \le A_i \le 100$ $(1 \le i \le N)$
  • $A_i \ne A_{i+1}$ $(1 \le i < N)$
  • $1 \le K \le 100$
  • All input values are integers.
  • $2 \le N \le 100$
  • $1 \le A_i \le 100$ $(1 \le i \le N)$
  • $A_i \ne A_{i+1}$ $(1 \le i < N)$
  • $1 \le K \le 100$
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入通过标准输入以如下格式给出:AI (CI翻译)

N K
A_1 A_2 \ldots A_N

N K
A_1 A_2 \ldots A_N
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Print the number of points on the polyline whose $y$-coordinate is $K$.

输出折线上 $y$ 坐标为 $K$ 的点的个数。AI (CI翻译)

样例

Input #1
5 3
1 3 1 5 1
Output #1
3
As shown in the figure below, there are $3$ points satisfying the condition: $(2,3)$, $(\frac{7}{2},3)$, and $(\frac{9}{2},3)$. Note that the point $(2,3)$ is a common endpoint of the segment connecting points $1$ and $2$ and the segment connecting points $2$ and $3$, but it is counted as one point. ![image](https://img.atcoder.jp/abc481/6b091bccaf9c134909377119703ded9f.png)
Input #2
3 3
3 1 3
Output #2
2
There are $2$ points satisfying the condition: $(1,3)$ and $(3,3)$. Note that the points at the ends of the polyline are also counted.
Input #3
2 100
1 2
Output #3
0
题目信息
题号
abc481_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。