PDP-38 (2026) - Phase A - 2 (ovens)
View as PDFWriting
Takis's Ovens
Another day of hard work has come to an end, and it is time for the pizzeria to close. However, there is a problem! Today, Takis's assistant took the day off, and Takis does not know how to turn off his ovens by himself.
Specifically, the pizzeria has ovens, numbered from
to
, and correspondingly
switches.
Some of the ovens are initially on, while the others are initially off.
We denote the initial state of the
-th oven by
:
if it is on and
if it is off.
The pizzeria's switches work in a special way: using the -th switch flips the state of the
-th oven and the next
ovens (where
is the "characteristic number" of the
-th switch); that is, the ovens among them that are on are turned off, and those that are off are turned on.
Takis must turn off all the ovens, but since he is in a hurry, he wants to do so as quickly as possible. What is the minimum number of switches he needs to use to achieve this?
Problem
Write a C++ program that reads the input data from oven.in and writes the results to oven.out.
Input Files (ovens.in)
The first line contains an integer : the number of ovens and switches in the pizzeria.
The second line contains integers
,
,
,
: the initial states of the ovens, where
represents an oven that is on and
represents an oven that is off.
The third line contains integers
,
,
,
: the characteristic numbers of the switches.
Output Files (ovens.out)
The output must contain a single line with an integer: the minimum number of switches Takis needs to use to turn off all the ovens.
Sample Input and Output Files
Input:
6
1 0 0 1 1 0
3 2 3 1 1 0
Output:
3
Explanation:
Takis can turn off all the ovens using switches, as follows:
He uses the
-th switch, which flips the state of the
-th oven and the next oven. The state of the ovens becomes
.
He uses the
-nd switch, which flips the state of the
-nd oven and the next two ovens. The state of the ovens becomes
.
He uses the
-st switch, which flips the state of the
-st oven and the next three ovens. The state of the ovens becomes
.
Furthermore, it can be proven that Takis cannot turn off all the ovens using fewer than switches.
Therefore, the answer is
.
Constraints
Subtasks
- (11 points)
for every
(where \(1 \\le i \le N\)).
- (17 points)
for every
(where \(1 \\le i \le N\)).
- (21 points)
for every
(where \(1 \\le i \le N\)).
- (24 points)
for every
(where
).
- (27 points) There are no further restrictions.
Notes
- Formatting: In both the input and the output, each line ends with a
newlinecharacter. - Maximum execution time:
sec.
- Maximum available memory:
MB.
Warning: The answer may exceed and, in general, you may need to perform operations with numbers larger than those that can be represented by the basic
int type.
Also, make sure to read the input and print the output efficiently in problems that require it.
Comments