QOJ.ac

QOJ

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

#576. 单调性 2

统计

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

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

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

以及许多其他方案。

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

输入格式

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

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

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

输出格式

在标准输出的第一行,程序应输出一个整数 $m$,即实现方案 $s_1,s_2,…,s_k$ 的子序列的最大长度。

在第二行,输出该子序列 $a_{i_1},a_{i_2},…,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.