QOJ.ac

QOJ

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

#10243. 照顧 [A]

統計

照顧新生兒並非易事。總得有人隨時看顧,同時還有其他職責,而且照顧者偶爾也想睡覺……

照顧小 Bajtolinka 的共有 $n$ 個人。我們考慮時間區間 $[0, L)$,將其劃分為 $L$ 個單位長度的片段 $[i, i+1)$,對於每個片段,我們都知道誰正忙於其他職責。如果一個人沒有忙於其他職責,他可以照顧孩子或睡覺。

在考慮的時間內,每個人最多會睡覺並醒來一次。為了公平起見,我們希望安排照顧工作,使得每個人睡覺的時間長度 $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.