QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 2048 MB 満点: 100

#2799. 填字游戏

統計

为了吸引更多游客来到巴黎,安妮(Anne)想要在卢浮宫的立面上举办一场盛大的灯光秀。立面上有几层窗户,且窗户在垂直方向上是对齐的。安妮想出了一个主意:在窗户上展示巨大的字母,每个窗户展示一个字母,使得它们在水平和垂直方向上都能组成单词。

在一个给定的立面上,窗户排列成一个 $N$ 行 $M$ 列的矩形网格。安妮收集了一个包含 $A$ 个长度为 $N$ 的单词的列表,以及一个包含 $B$ 个长度为 $M$ 的单词的列表。她想知道,有多少种方法可以在该网格上同时展示 $N$ 个长度为 $M$ 的水平单词和 $M$ 个长度为 $N$ 的垂直单词。

输入格式

输入包含以下内容: 第一行包含两个整数 $N$ 和 $A$,中间用空格隔开。 第二行包含两个整数 $M$ 和 $B$,中间用空格隔开。 接下来的 $A$ 行包含长度为 $N$ 的单词,每行一个。 接下来的 $B$ 行包含长度为 $M$ 的单词,每行一个。

数据范围

输入满足 $2 \leqslant N, M \leqslant 4$ 且 $1 \leqslant A \times B \leqslant 1\,008\,016$。 单词取自英语词典。两个列表中的单词均无重复。单词由小写字母 'a'(ASCII 码 97)到 'z'(ASCII 码 122)组成。 第一个列表中的单词将垂直显示,从上到下。第二个列表中的单词将水平显示,从左到右。同一个单词可以多次用于构建网格,即如果它属于第一个(或第二个)单词列表,则可以在多个列(或行)中使用。 当 $N = M$ 时,不允许将第一个列表中的单词水平使用(除非它们同时也出现在第二个列表中),也不允许将第二个列表中的单词垂直使用(除非它们同时也出现在第一个列表中)。

输出格式

输出应包含一行,内容为一个整数,即不同单词网格的总数。

样例

样例输入 1

3 4
4 5
war
are
yes
sat
says
area
test
ways
rest

样例输出 1

2

说明 1

解决方案为:

s a y s
a r e a
t e s t
w a y s
a r e a
r e s t

样例输入 2

3 7
3 7
ran
age
now
its
the
set
ago
ran
age
now
its
the
set
ago

样例输出 2

2

说明 2

解决方案为:

i t s
t h e
s e t
r a n
a g o
n o w

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.