CF1140E.Palindrome-less Arrays

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let's denote that some array bb is bad if it contains a subarray bl,bl+1,…,brb_l, b_{l+1}, \dots, b_{r} of odd length more than 11 (l<rl \lt r and r−l+1r - l + 1 is odd) such that ∀i∈0,1,…,r−l\forall i \in {0, 1, \dots, r - l} bl+i=br−ib_{l + i} = b_{r - i}.

If an array is not bad, it is good.

Now you are given an array a1,a2,…,ana_1, a_2, \dots, a_n. Some elements are replaced by −1-1. Calculate the number of good arrays you can obtain by replacing each −1-1 with some integer from 11 to kk.

Since the answer can be large, print it modulo 998244353998244353.

我们称某个数组 bb 是“坏的”,如果它包含一个长度为大于 11 的奇数的子数组 bl,bl+1,…,brb_l, b_{l+1}, \dots, b_{r}(即 l<rl \lt r 且 r−l+1r - l + 1 为奇数),满足对所有 i∈{0,1,…,r−l}i \in \{0, 1, \dots, r - l\},均有 bl+i=br−ib_{l + i} = b_{r - i}。

若一个数组不是“坏的”,则称其为“好的”。

现给你一个数组 a1,a2,…,ana_1, a_2, \dots, a_n,其中部分元素被替换为 −1-1。你需要计算:将每个 −1-1 替换为 11 到 kk 之间的某个整数后,能构成多少个“好的”数组。

由于答案可能很大,请输出其对 998244353998244353 取模的结果。

输入格式

The first line contains two integers nn and kk (2≤n,k≤2⋅1052 \le n, k \le 2 \cdot 10^5) — the length of array aa and the size of "alphabet", i. e., the upper bound on the numbers you may use to replace −1-1.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (ai=−1a_i = -1 or 1≤ai≤k1 \le a_i \le k) — the array aa.

第一行包含两个整数 nn 和 kk(2≤n,k≤2⋅1052 \le n, k \le 2 \cdot 10^5)—— 分别表示数组 aa 的长度以及“字母表”的大小,即用于替换 −1-1 的数字的上界。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(每个 aia_i 要么为 −1-1,要么满足 1≤ai≤k1 \le a_i \le k)—— 即数组 aa。

输出格式

Print one integer — the number of good arrays you can get, modulo 998244353998244353.

输出一个整数——你能得到的好数组的数量,对 998244353998244353 取模。

输入输出样例

  • 输入#1

    2 3
    -1 -1

    输出#1

    9
  • 输入#2

    5 2
    1 -1 -1 1 2

    输出#2

    0
  • 输入#3

    5 3
    1 -1 -1 1 2

    输出#3

    2
  • 输入#4

    4 200000
    -1 -1 12345 -1

    输出#4

    735945883

输入解题思路,AI测评打分。不知道怎么写?

首页