#P9969. [THUPC 2024 初赛] 分治乘法
[THUPC 2024 初赛] 分治乘法
Problem Description
Xiao Ai wants to challenge divide-and-conquer multiplication. They abstract the strategy into the following problem:
You are given a target set , which is a subset of (). You need to construct some sets through a sequence of operations and finally obtain . Specifically, there are three types of operations:
- Create a set of size one, .
- Union two disjoint sets that have already been constructed, obtaining .
- Translate (shift) a set that has already been constructed, i.e., .
A constructed set can be used multiple times later. Meanwhile, you must ensure that all sets appearing during the process are subsets of .
Your cost is the sum of the sizes of all constructed sets. You do not need to minimize the cost; you only need to keep the cost not exceeding . The number of operations you use should also not exceed .
Input Format
The first line contains a positive integer .
The next line contains a 01 string of length . The -th character is 1 means , otherwise . It is guaranteed that is non-empty.
Output Format
The first line outputs a positive integer , the number of operations you used.
In the next lines, each line describes an operation. Let the set produced by the -th operation be :
1 xmeans creating a set of size one .2 x ymeans unioning the disjoint sets .3 x ymeans translating a constructed set, i.e., .
You must ensure all operations satisfy the requirements, and the set produced by the last operation is exactly .
5
11011
5
1 1
1 4
2 1 2
3 3 1
2 3 4
Hint
Sample #1 Explanation
- Operation 1: create the set .
- Operation 2: create the set .
- Operation 3: union to get .
- Operation 4: translate by to get .
- Operation 5: union to get . This gives .
The total cost of this plan is .
Hint
If your complexity is good, please trust the constant factor.
Problem Usage Agreement
From the THUPC2024 (Tsinghua University Student Programming Contest and Intercollegiate Invitational Contest 2024) Preliminary.
The following “this repository” refers to the THUPC2024 Preliminary official repository (https://github.com/ckw20/thupc2024_pre_public).
-
Any organization or individual may use or repost the problems in this repository for free.
-
Any organization or individual, when using the problems in this repository, should make them free of charge and publicly accessible. It is strictly forbidden to profit from these problems or to add special permissions to these problems.
-
If conditions allow, when using the problems in this repository, please also provide ways to obtain resources such as testdata, reference solutions, and editorials. Otherwise, please attach the GitHub address of this repository.
Translated by ChatGPT 5