#P7967. [COCI 2021/2022 #2] Magneti
[COCI 2021/2022 #2] Magneti
Problem Description
You are given magnets and empty slots. The distance between adjacent slots is , and each slot can hold one magnet. All magnets must be placed. Each magnet can attract other magnets whose distance is less than .
Find the total number of ways to place the magnets so that no two magnets attract each other, modulo .
Input Format
The first line contains two positive integers , representing the number of magnets and the number of slots.
The second line contains integers .
Output Format
Output the total number of valid ways modulo .
1 10
10
10
4 4
1 1 1 1
24
3 4
1 2 1
4
Hint
Sample 2 Explanation: All permutations of the four magnets satisfy the requirements.
Sample 3 Explanation:
Use to represent magnets, and to represent an empty slot. Then all valid arrangements are: , , , and .
Constraints
This problem uses bundled subtasks.
- Subtask 1 (10 pts): .
- Subtask 2 (20 pts): .
- Subtask 3 (30 pts): , .
- Subtask 4 (50 pts): No special restrictions.
For of the testdata, , , .
Hints and Notes
Translated from COCI 2021-2022 CONTEST #2 Task 4 Magneti.
The score settings follow the original COCI problem, with a full score of .
Translated by ChatGPT 5