QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 32 MB Total points: 100

#22362. 秘密訊息

Statistics

Bessie 帶領乳牛企圖逃跑!為此,乳牛互相傳送秘密二進位訊息。

一貫聰明的反間諜 Farmer John 截獲了 $M$ 則訊息,$(1 \le M \le 50,000)$,每則的前 $b_{i}$ 位元,$(1 \le b_{i} \le 10,000)$。

他列出認為乳牛在使用的 $N$ 個不完整碼字,$(1 \le N \le 50,000)$。遺憾的是,只知道碼字 $j$ 的前 $c_{j}$ 位元,$(1 \le c_{j} \le 10,000)$。

對每個碼字 $j$,計算多少則截獲訊息與它匹配,即訊息和碼字的開頭位元相同。你的任務是求這個數。

輸入總位元數,即 $b_{i}$ 與 $c_{j}$ 之和,不超過 $500,000$。

輸入格式

  • 第 $1$ 行:整數 $M$、$N$。

  • 第 $2,\ldots,M+1$ 行:第 $i+1$ 行描述截獲訊息 $i$,先是整數 $b_{i}$,再是以空格分隔的 $b_{i}$ 個 0 或 1。

  • 第 $M+2,\ldots,M+N+1$ 行:第 $M+j+1$ 行描述碼字 $j$,先是整數 $c_{j}$,再是以空格分隔的 $c_{j}$ 個 0 或 1。

輸出格式

  • 第 $1,\ldots,M$ 行:第 $j$ 行是第 $j$ 個碼字可匹配的訊息數。

範例

輸入格式 1

4 5
3 0 1 0
1 1
3 1 0 0
3 1 1 0
1 0
1 1
2 0 1
5 0 1 0 0 1
2 1 1

輸出格式 1

1
3
1
1
2

說明

四則訊息、五個碼字。訊息開頭為 010、1、100、110;碼字開頭為 0、1、01、01001、11。

0 只匹配 010:$1$ 則;1 匹配 1、100、110:$3$ 則;01 只匹配 010:$1$ 則;01001 匹配 010:$1$ 則;11 匹配 1、110:$2$ 則。

題目作者:David Benjamin 和 Jacob Steinhardt,2008

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.