QOJ.ac

QOJ

时间限制: 1 s 内存限制: 256 MB 总分: 100

#575. 单调性

统计

对于一个整数序列 $a_1, a_2, \dots, a_n$,我们定义其单调性方案为由符号 <, >, = 组成的序列 $s_1, s_2, \dots, s_{n-1}$。符号 $s_i$ 表示 $a_i$ 与 $a_{i+1}$ 之间的关系。例如,序列 2, 4, 3, 3, 5, 3 的单调性方案为 <, >, =, <, >

我们称一个单调性方案为 $s_1, s_2, \dots, s_n$ 的整数序列 $b_1, b_2, \dots, b_{n+1}$ 实现了另一个单调性方案 $s'_1, s'_2, \dots, s'_k$,如果对于每一个 $i=1, 2, \dots, n$,都有 $s_i = s'_{(i-1) \bmod k + 1}$。换句话说,序列 $s_1, s_2, \dots, s_n$ 可以通过重复序列 $s'_1, s'_2, \dots, s'_k$ 并截去该重复序列末尾适当的部分得到。例如,序列 2, 4, 3, 3, 5, 3 实现了以下每一个方案:

  • <, >, =
  • <, >, =, <, >
  • <, >, =, <, >, <, <, =
  • <, >, =, <, >, =, >, >

以及许多其他方案。

给定一个整数序列 $a_1, a_2, \dots, a_n$ 和一个单调性方案 $s_1, s_2, \dots, s_k$。你的任务是找到前者的最长子序列 $a_{i_1}, a_{i_2}, \dots, a_{i_m}$ ($1 \le i_1 < i_2 < \dots < i_m \le n$),使其实现了该方案。

输入

标准输入的第一行包含两个整数 $n$ 和 $k$ ($1 \le n \le 20\,000$, $1 \le k \le 100$),由单个空格分隔,分别表示序列 ($a_i$) 和单调性方案 ($s_j$) 的长度。

第二行给出序列 ($a_i$),即包含 $n$ 个由单个空格分隔的整数 $a_i$ ($1 \le a_i \le 1\,000\,000$)。

最后,第三行给出单调性方案 ($s_j$),即包含 $k$ 个由单个空格分隔的符号 $s_j$(形式为 <, >, =)。

输出

在标准输出的第一行,你的程序应输出一个整数 $m$,即实现方案 $s_1, s_2, \dots, s_k$ 的子序列 $a_{i_1}, a_{i_2}, \dots, a_{i_m}$ 的最大长度。

在第二行,输出该子序列的元素,元素之间用单个空格分隔。

样例

输入格式 1

7 3
2 4 3 1 3 5 3
< > =

输出格式 1

6
2 4 3 3 5 3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.