A. Odds and Ends

Codeforces
IDCF849A
Time1000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
_Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?_ Given an integer sequence _a_1, _a_2, ..., _a__n_ of length _n_. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers. A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not. ## Input The first line of input contains a non-negative integer _n_ (1 ≤ _n_ ≤ 100) — the length of the sequence. The second line contains _n_ space-separated non-negative integers _a_1, _a_2, ..., _a__n_ (0 ≤ _a__i_ ≤ 100) — the elements of the sequence. ## Output Output "_Yes_" if it's possible to fulfill the requirements, and "_No_" otherwise. You can output each letter in any case (upper or lower). [samples] ## Note In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met. In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}. In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met. In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
_Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?_ 给定一个长度为 #cf_span[n] 的整数序列 #cf_span[a1, a2, ..., an]。判断是否能将其划分为奇数个非空子段,使得每个子段的长度为奇数,且首尾元素均为奇数。 #cf_span(class=[tex-font-style-underline], body=[subsegment]) 是整个序列的一个连续子序列。例如,#cf_span[{3, 4, 5}] 和 #cf_span[{1}] 是序列 #cf_span[{1, 2, 3, 4, 5, 6}] 的子段,而 #cf_span[{1, 2, 4}] 和 #cf_span[{7}] 则不是。 输入的第一行包含一个非负整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 100]) —— 序列的长度。 第二行包含 #cf_span[n] 个用空格分隔的非负整数 #cf_span[a1, a2, ..., an] (#cf_span[0 ≤ ai ≤ 100]) —— 序列的元素。 如果能满足要求,输出 "_Yes_";否则输出 "_No_"。 你可以以任意大小写输出每个字母。 在第一个例子中,将序列划分为 #cf_span[1] 个子段:#cf_span[{1, 3, 5}],即可满足要求。 在第二个例子中,将序列划分为 #cf_span[3] 个子段:#cf_span[{1, 0, 1}]、#cf_span[{5}]、#cf_span[{1}]。 在第三个例子中,某个子段必须以 #cf_span[4] 开头,而 4 是偶数,因此无法满足要求。 在第四个例子中,序列可以划分为 #cf_span[2] 个子段:#cf_span[{3, 9, 9}]、#cf_span[{3}],但这不是合法解,因为 #cf_span[2] 是偶数。 ## Input 输入的第一行包含一个非负整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 100]) —— 序列的长度。第二行包含 #cf_span[n] 个用空格分隔的非负整数 #cf_span[a1, a2, ..., an] (#cf_span[0 ≤ ai ≤ 100]) —— 序列的元素。 ## Output 如果能满足要求,输出 "_Yes_";否则输出 "_No_"。你可以以任意大小写输出每个字母。 [samples] ## Note 在第一个例子中,将序列划分为 #cf_span[1] 个子段:#cf_span[{1, 3, 5}],即可满足要求。在第二个例子中,将序列划分为 #cf_span[3] 个子段:#cf_span[{1, 0, 1}]、#cf_span[{5}]、#cf_span[{1}]。在第三个例子中,某个子段必须以 #cf_span[4] 开头,而 4 是偶数,因此无法满足要求。在第四个例子中,序列可以划分为 #cf_span[2] 个子段:#cf_span[{3, 9, 9}]、#cf_span[{3}],但这不是合法解,因为 #cf_span[2] 是偶数。
**Definitions** Let $ n \in \mathbb{Z}_{\geq 0} $ be the length of the sequence. Let $ A = (a_1, a_2, \dots, a_n) $ be a sequence of non-negative integers. A *subsegment* is a contiguous subsequence $ (a_i, a_{i+1}, \dots, a_j) $ for some $ 1 \leq i \leq j \leq n $. A subsegment is *valid* if: - Its length $ j - i + 1 $ is odd, - Both endpoints $ a_i $ and $ a_j $ are odd. **Constraints** 1. $ 1 \leq n \leq 100 $ 2. $ 0 \leq a_i \leq 100 $ for all $ i \in \{1, \dots, n\} $ **Objective** Determine whether there exists a partition of $ A $ into $ k $ non-overlapping, contiguous, valid subsegments, such that: - $ k $ is an odd positive integer, - Every element of $ A $ belongs to exactly one subsegment. Output "Yes" if such a partition exists; otherwise, output "No".
Samples
Input #1
3
1 3 5
Output #1
Yes
Input #2
5
1 0 1 5 1
Output #2
Yes
Input #3
3
4 3 1
Output #3
No
Input #4
4
3 9 9 3
Output #4
No
API Response (JSON)
{
  "problem": {
    "name": "A. Odds and Ends",
    "description": {
      "content": "_Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?_ Given an integer sequence _a_1, _a_2, ..., _a__n_ of length _n_. Decide whether it is possible to divid",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF849A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "_Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?_\n\nGiven an integer sequence _a_1, _a_2, ..., _a__n_ of length _n_. Decide whether it is possible to divid...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "_Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?_\n\n给定一个长度为 #cf_span[n] 的整数序列 #cf_span[a1, a2, ..., an]。判断是否能将其划分为奇数个非空子段,使得每个子段的长度为奇数,且首尾元素均为奇数。\n\n#cf_span...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}_{\\geq 0} $ be the length of the sequence.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of non-negative integers.\n\nA *subsegment* is a contiguous subseque...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments