CF1474F.1 2 3 4 ...

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Igor had a sequence d1,d2,…,dnd_1, d_2, \dots, d_n of integers. When Igor entered the classroom there was an integer xx written on the blackboard.

Igor generated sequence pp using the following algorithm:

  1. initially, p=[x]p = [x];
  2. for each 1≤i≤n1 \leq i \leq n he did the following operation ∣di∣|d_i| times:
    • if di≥0d_i \geq 0, then he looked at the last element of pp (let it be yy) and appended y+1y + 1 to the end of pp;
    • if di<0d_i \lt 0, then he looked at the last element of pp (let it be yy) and appended y−1y - 1 to the end of pp.

For example, if x=3x = 3, and d=[1,−1,2]d = [1, -1, 2], pp will be equal [3,4,3,4,5][3, 4, 3, 4, 5].

Igor decided to calculate the length of the longest increasing subsequence of pp and the number of them.

A sequence aa is a subsequence of a sequence bb if aa can be obtained from bb by deletion of several (possibly, zero or all) elements.

A sequence aa is an increasing sequence if each element of aa (except the first one) is strictly greater than the previous element.

For p=[3,4,3,4,5]p = [3, 4, 3, 4, 5], the length of longest increasing subsequence is 33 and there are 33 of them: [3‾,4‾,3,4,5‾][\underline{3}, \underline{4}, 3, 4, \underline{5}], [3‾,4,3,4‾,5‾][\underline{3}, 4, 3, \underline{4}, \underline{5}], [3,4,3‾,4‾,5‾][3, 4, \underline{3}, \underline{4}, \underline{5}].

伊戈尔有一个整数序列 d1,d2,…,dnd_1, d_2, \dots, d_n。当他进入教室时,黑板上已写有一个整数 xx。

伊戈尔使用如下算法生成序列 pp:

  1. 初始时,p=[x]p = [x];
  2. 对每个 1≤i≤n1 \leq i \leq n,他执行以下操作 ∣di∣|d_i| 次:
    • 若 di≥0d_i \geq 0,则查看 pp 的最后一个元素(记为 yy),并将 y+1y + 1 追加到 pp 末尾;
    • 若 di<0d_i \lt 0,则查看 pp 的最后一个元素(记为 yy),并将 y−1y - 1 追加到 pp 末尾。

例如,若 x=3x = 3,且 d=[1,−1,2]d = [1, -1, 2],则 p=[3,4,3,4,5]p = [3, 4, 3, 4, 5]。

伊戈尔决定计算 pp 的最长递增子序列的长度及其个数。

序列 aa 是序列 bb 的一个子序列,当且仅当 aa 可通过从 bb 中删除若干(可能为零个或全部)元素得到。

序列 aa 是一个递增序列,当且仅当其每个元素(除第一个外)均严格大于前一个元素。

对于 p=[3,4,3,4,5]p = [3, 4, 3, 4, 5],最长递增子序列的长度为 33,且共有 33 个:[3‾,4‾,3,4,5‾][\underline{3}, \underline{4}, 3, 4, \underline{5}]、[3‾,4,3,4‾,5‾][\underline{3}, 4, 3, \underline{4}, \underline{5}]、[3,4,3‾,4‾,5‾][3, 4, \underline{3}, \underline{4}, \underline{5}]。

输入格式

The first line contains a single integer nn (1≤n≤501 \leq n \leq 50) — the length of the sequence dd.

The second line contains a single integer xx (−109≤x≤109-10^9 \leq x \leq 10^9) — the integer on the blackboard.

The third line contains nn integers d1,d2,…,dnd_1, d_2, \ldots, d_n (−109≤di≤109-10^9 \leq d_i \leq 10^9).

第一行包含一个整数 nn(1≤n≤501 \leq n \leq 50)——序列 dd 的长度。

第二行包含一个整数 xx(−109≤x≤109-10^9 \leq x \leq 10^9)——黑板上的整数。

第三行包含 nn 个整数 d1,d2,…,dnd_1, d_2, \ldots, d_n(−109≤di≤109-10^9 \leq d_i \leq 10^9)。

输出格式

Print two integers:

  • the first integer should be equal to the length of the longest increasing subsequence of pp;
  • the second should be equal to the number of them modulo 998244353998244353.

You should print only the second number modulo 998244353998244353.

输出两个整数:

  • 第一个整数应等于排列 pp 的最长递增子序列的长度;
  • 第二个整数应等于最长递增子序列的个数对 998244353998244353 取模的结果。

你只需输出第二个数对 998244353998244353 取模的结果。

输入输出样例

  • 输入#1

    3
    3
    1 -1 2

    输出#1

    3 3
  • 输入#2

    3
    100
    5 -3 6

    输出#2

    9 7
  • 输入#3

    3
    1
    999999999 0 1000000000

    输出#3

    2000000000 1
  • 输入#4

    5
    34
    1337 -146 42 -69 228

    输出#4

    1393 3876

说明/提示

The first test case was explained in the statement.

In the second test case p=[100,101,102,103,104,105,104,103,102,103,104,105,106,107,108]p = [100, 101, 102, 103, 104, 105, 104, 103, 102, 103, 104, 105, 106, 107, 108].

In the third test case p=[1,2,…,2000000000]p = [1, 2, \ldots, 2000000000].

第一个测试用例已在题目描述中说明。

第二个测试用例中,p=[100,101,102,103,104,105,104,103,102,103,104,105,106,107,108]p = [100, 101, 102, 103, 104, 105, 104, 103, 102, 103, 104, 105, 106, 107, 108]。

第三个测试用例中,p=[1,2,…,2000000000]p = [1, 2, \ldots, 2000000000]。

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

首页