QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 1024 MB Total points: 10

#10243. 照顾 [A]

統計

照顾新生儿并非易事。总得有人看护它。此外,人们还有其他职责,而且看护者有时也想睡觉……

共有 $n$ 个人参与照顾小 Bajtolinka。我们考虑时间区间 $[0, L)$,将其划分为 $L$ 个单位时间片段 $[i, i+1)$,并且对于每个片段,我们都知道谁正忙于其他职责。如果一个人没有忙于其他职责,他就可以看护孩子或睡觉。

在考虑的时间段内,每位 $n$ 个人最多睡觉一次(即睡着并醒来一次)。为了公平起见,我们希望安排看护工作,使得每个人睡觉的时间长度恰好相同,均为 $T$(其中 $T$ 是一个非负实数)。其他职责占用完整的片段 $[i, i+1)$,而睡眠可以占用任意区间 $[a, a+T)$,其中 $a$ 是满足 $a+T \le L$ 的非负实数。

请找出最大的 $T$,使得可以安排所有 $n$ 个人的睡眠,从而对于每个实数 $x \in [0, L)$,至少有一人可以在时刻 $x$ 看护 Bajtolinka(即该人既没有睡觉,也没有忙于其他职责)。可以证明,最优的 $T$(如果存在)是一个有理数。请将其以最简分数形式输出。如果无法安排计划使得在整个考虑期间都有人照顾孩子,请输出 $-1$。

输入格式

输入的第一行包含两个整数 $n, L$ ($1 \le n \le 18, 1 \le L \le 100\,000$),分别表示照顾 Bajtolinka 的人数和考虑的时间区间长度。

接下来的 $n$ 行包含长度为 $L$ 的字符串,由字符 X.(点)组成,描述了每个人在各个时间片段中的其他职责,其中第 $i$ 个字符描述了区间 $[i-1, i)$。

  • 字符 X 表示该人忙于其他职责。
  • 字符 . 表示该人是空闲的——可以睡觉或看护 Bajtolinka。

输出格式

如果无法制定计划,输出一行 $-1$。否则,输出一行一个有理数,以最简分数形式 $x/y$ 表示(满足 $\text{gcd}(x, y) = 1$ 且 $y > 0$),即在最优看护安排下,每个人能获得的最大睡眠时长。

样例

样例输入 1

3 6
..X.XX
.X..X.
X..X..

样例输出 1

4/3

样例输入 2

3 2
..
XX
..

样例输出 2

0/1

样例输入 3

1 3
.X.

样例输出 3

-1

说明

在第一个样例中,为了获得结果 $4/3$,人们必须分别在区间 $[0, 4/3), [8/3, 4), [4/3, 8/3)$ 内睡觉。

在第二个样例中,第二个人一直忙于其他职责,因此没有时间睡觉。

在第三个样例中,在时刻 $x = \pi/2 \approx 1.57$ 时,没有人能照顾 Bajtolinka。

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.