0% found this document useful (0 votes)
26 views

Strangeoperation (It)

The document describes a problem where Doctor Strange is given two integer arrays A and B of length N and can perform an operation on array A to make its elements equal -1*(A[i-1] + A[i] + A[i+1]). The task is to determine if it is possible to make A equal to B through these operations and the minimum number of operations required. The input and output formats are described along with examples and scoring details for different subtasks based on array size and constraints.

Uploaded by

braagamer82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Strangeoperation (It)

The document describes a problem where Doctor Strange is given two integer arrays A and B of length N and can perform an operation on array A to make its elements equal -1*(A[i-1] + A[i] + A[i+1]). The task is to determine if it is possible to make A equal to B through these operations and the minimum number of operations required. The input and output formats are described along with examples and scoring details for different subtasks based on array size and constraints.

Uploaded by

braagamer82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

I ( O T IIOT2024 – Round 3 

+ I ) ; Online, January 17-18th, 2024 strangeoperation • EN

Strange Operation (strangeoperation)


Doctor Strange found two integer arrays of length N , namely A0 , . . . , AN −1 and B0 , . . . , BN −1 . He can
perform the following operation on A any number of times:

• Choose an index 1 ≤ i ≤ N − 2 and let Ai := −(Ai−1 + Ai + Ai+1 ). That is, assign the value
−(Ai−1 + Ai + Ai+1 ) to Ai .

Figure 1: Dr. Strange is preparing to perform some operations.

Help the Doctor determine whether it is possible to make the array A equal to B and if so, then find the
minimum number of operations required to achieve this.

+ Among the attachments of this task you may find a template file strangeoperation.* with
a sample incomplete implementation.

Input
The first line contains the only integer N . The second line contains N integers, the elements of array A.
The third line contains N integers, the elements of array B.

Output
You need to write a single line with an integer: the minimum number of operations required to make A
equal to B, or −1 if it is not possible to do so.

Constraints
• 2 ≤ N ≤ 200 000.
• −109 ≤ Ai , Bi ≤ 109 for each i = 0 . . . N − 1.

strangeoperation Page 1 of 2
Scoring
Your program will be tested against several test cases grouped in subtasks. In order to obtain the score
of a subtask, your program needs to correctly solve all of its test cases.
In this task, you can get partial scores: you will get 50% of the points for a subtask if you successfully
determine whether it is possible to make A equal to B (but do not correctly solve all of its test cases).
For this, the following condition must be satisfied for all test cases in a subtask: you should output −1
whenever it is impossible to make the two arrays equal, and otherwise, you should output a non-negative
integer between 0 and 263 − 1.
– Subtask 1 (0 points) Examples.

– Subtask 2 (15 points) There is at most one non-zero number in A.

– Subtask 3 (18 points) N ≤ 7.

– Subtask 4 (50 points) N ≤ 1000.

– Subtask 5 (17 points) No additional limitations.


Examples
input output

6 3
2 7 1 8 2 8
2 -10 1 -11 1 8

4 -1
3 1 4 1
-4 1 -6 1

Explanation
In the first sample case, consider the following steps for the array A = [2, 7, 1, 8, 2, 8]:

• Perform the operation on index 3. The array becomes: [2, 7, 1, −11, 2, 8].

• Perform the operation on index 1. The array becomes: [2, −10, 1, −11, 2, 8].

• Perform the operation on index 4. The array becomes: [2, −10, 1, −11, 1, 8].

It is not possible to make the two arrays equal in less than 3 moves.
In the second sample case, it can be proven that there is no way to make A equal to B using the
described operation.

strangeoperation Page 2 of 2

You might also like