#P9589. 「PFLOI R1」PFL 除法
「PFLOI R1」PFL 除法
Background
Is it necessary to connect the backgrounds of all contest problems together.
Just like that, the door to a new world opened to them...
"Meow!" A cute calico cat greeted them.
"Did you just arrive here?"
"Mm."
"I'll show you around. After all, I'm so cute!"
"..." The calico cat suddenly stopped, looked over the sequence in its hands, and then smiled again:
"But you have to answer my question first."
Problem Description
The calico cat has a sequence of length and another sequence of length . You may perform the following operation any number of times:
- Choose two integers and such that , , and , then change to .
Note: Each element in and can be chosen and operated on multiple times.
In the end, make all elements in equal. Please output the minimum number of operations. If there is no solution, output -1.
Input Format
The first line contains two positive integers and .
The second line contains positive integers representing sequence .
The third line contains positive integers representing sequence .
Output Format
Output one integer representing the minimum number of operations. If there is no solution, output -1.
4 5
16 24 28 36
11 4 7 3 2
6
2 3
11 13
13 1 11
2
2 2
2 3
4 5
-1
Hint
This problem uses bundled tests.
| Subtask ID | Special Property | Score |
|---|---|---|
| All elements in are equal. | ||
| None. |
For all data, , .
Translated by ChatGPT 5