QOJ.ac

QOJ

Límite de tiempo: 1.0 s Límite de memoria: 512 MB Puntuación total: 100 Hackeable ✓

#9288. 罗马回文

Estadísticas

给定一个由字母 ‘I’、‘V’、‘X’、‘L’、‘C’、‘D’ 和 ‘M’ 组成的字符串 $S$。你的任务是将该字符串分割为最少数量的子串,使得每个子串满足:

  • 是书写正确的罗马数字;
  • 是回文串。

下表展示了罗马数字的书写方式:

个位数值 千位 百位 十位 个位
1 M C X I
2 MM CC XX II
3 MMM CCC XXX III
4 CD XL IV
5 D L V
6 DC LX VI
7 DCC LXX VII
8 DCCC LXXX VIII
9 CM XC IX

说明:

  • 4、9、40、90、400 和 900 的表示使用“减法记数法”,即较小的符号从较大的符号中减去(例如,40 (“XL”) 是从 ‘L’ (50) 中减去 ‘X’ (10))。这是标准用法中仅有的减法形式。
  • 包含多个十进制位的数字是通过按从高到低的顺序拼接每个位对应的罗马数字构成的。
  • 任何缺失的数位(在位值表示中为零)将被省略。
  • 罗马数字表示法中能表示的最大数字是 3,999 (MMMCMXCIX)。

输入格式

第一行包含一个整数 $n$ — 字符串的长度 ($1 \le n \le 100\,000$)。 第二行包含长度为 $n$ 的字符串,由字母 ‘I’、‘V’、‘X’、‘L’、‘C’、‘D’ 和 ‘M’ 组成。

输出格式

第一行输出一个整数 $k$ — 将给定字符串拼接成最少数量的正确罗马数字回文串的个数。随后输出 $k$ 行,每行包含一个字符串 — 一个既是正确罗马数字又是回文串的子串,使得按输出顺序拼接所有 $k$ 行字符串后等于给定的字符串。

如果存在多种解,输出其中任意一种即可。

样例

输入 1

5
MMXXI

输出 1

3
MM
XX
I

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.