Editorial for JOI '23 Open P1 - Ancient Machine 2
Submitting an official solution before solving the problem yourself is a bannable offence.
Author: Tomohito Hoshii
Introduction
In this review, we only explain solutions which lead to full score solutions. However, there are other solutions which give good results but do not lead to full score solutions.
In the following, the indices of elements of arrays are zero-based (i.e. they start from ), and "the value set in
the memory area of the machine" is called "the state" of the machine.
(10 points)
We can determine the -th character by
. Concretely, we construct the sequences as follows.
The -th character is
0
if the final state is , and it is
1
if the final state is .
Since , we determine each character one-by-one from the first one, and get a solution with
.
(10 points)
For the characters from the last one, it is possible to determine whether the string
coincides with the
string
or not by
.
For example, if
101
, we construct as follows.
The current state is if the characters are the same until the
-th character of
.
If the final state is , the last characters coincide with
; otherwise, the last characters do not coincide with
.
By this method, we determine the characters from the last one, and get a solution with .
(37 points)
We use an solution as above for the first half of characters (
characters), and use an
solution as above for the last half of characters (
characters). Combining them, we get a solution with
.
(97 points)
We can achieve using linear algebra.
There are unknown quantities. We would like to have
independent linear equations in
variables. Since we know each quantity is either
or
, we can consider equations mod
.
Concretely, we proceed as follows.
We get the sum of 's (mod
) for every
with
(mod
) by
. Here we choose the values
of
and
by row reduction (or Gaussian elimination) so that the vectors for chosen
and
(for example,
if
and
) are linearly independent.
We can find linearly independent vectors in the range
. Hence we get a solution with
.
(100 points)
Combining an solution and an
solution, we achieve
as follows.
To get information on a particular character amounts to choose the vector .
Up to , we determine the first
characters and the last
characters; hence we get
vectors.
Additionally, in the range
, we get
vectors such that the
vectors are linearly
independent. Hence we get a solution with
.
Comments