Você está na página 1de 4

ABC042 / ARC058 Commentary

Kazuma Mikami ( kyuridenamida) / Akirataira Morita ( yosupo)

A Problem Japanese Iroha-chan Easy


Character string A, B, C In, the length of the Five Is a string 2 One, length 7 Is a string 1 One limited to when there is, it is possible to make the five

hundred seventy-five.

B Problem string love Iroha-chan Easy


All the length of all of the strings L From the condition that it rearranges the string given the lexicographically in ascending order, it is possible

to achieve a lexicographically smallest when coupled in this order.

In general, even if the length of the string is different, 2 One of the string a, b For a But b The smaller it a + b <b + a And

defining, those sorts character strings can be achieved lexicographically smallest when coupled in ascending order based on

their. Proof will be omitted.

C Problem Good's Iroha-chan


{ 1, 2, 3, Four, Five, 6, 7, 8, 9} / { D 1, D 2, ..., D N} Since it is guaranteed is, 0 Deer used
For example there is no such a case is not always solution exists.

The type of if available numbers 1 Even it was as, them N Than the number of digits 1 Often for considering as many side-by-side the number it is the

upper limit of the solution One, the upper limit of the solution Ten N It is. N, N + 1, N + 2, ...

For sure satisfies the condition of the solution in this order, in time with solution that you output the number of time it is found satisfy the

conditions.

The time complexity of the whole O (N log N) It is.

D Problem Iroha-chan and squares

method of calculating the inverse element has been modified because there was a clerical error for. I'm sorry. ( 7/24)

The upper left corner of the coordinates ( 0, 0) , The lower right coordinates ( H - 1, W - 1) And it is.

B i W All of which satisfy the i about, ( 0, 0), ( H - A - 1, i), (H - A, i), (H - 1, W - 1)


The counting of the number of paths through the order, by summing them, the path finding just enough are counted.
Drawing 1 I explain that this is.
It is given on the basis of the above concept, under y Times, to the right x It is necessary to obtain the number of paths so as to move round efficiently,

but this is C (x + y, x) be equivalent to ( C (n, r) It is n In either et al number of things r It represents the number of combinations to choose pieces).

C (n, r) = n! r! (n - r)! Since it is, 0 x H + W - 2 Against x! ( mod 10 9 + 7) When


( x!) - 1 ( mod 10 9 + 7) In advance O (H + W) By keeping in the table were calculated by multiplying, each

1
C (n, r) It is O ( 1) It can be obtained at. Ten 9 + 7 Since prime, the following is true.

x 0 (mod 10 9 + 7) All of not x For x - 1 ( mod 10 9 + 7) There exist.

Than Fermat's little theorem x - 1 x Ten 9+ Five( mod 10 9 + 7) It is.

Therefore, floor multiplier inverse element ( x!) - 1 ( x!) Ten 9+ Five( mod 10 9 + 7) The calculated in a suitable manner, such as binary exponentiation may if obtained

in advance. The order of the two-minute power method O ( 1) In there is a constant multiple is 30

Beware that there enough times. By the way, the maximum value of the floor multiplier to be determined M! As, first to the inverse element ( M!) -

1 The after obtaining a binary exponentiation, to the number M Multiplied by (( M - 1)!) - 1 In the Motomari, their number M - 1 Multiplied by (( M - 2)!)

- 1 It is Motomari, ..., but it is possible to construct a reverse original table calculated in by Ri fast if we in Fu that, but need not this time.

E Problem Japanese Iroha-chan

Anywhere XYZ Kazoeagere the number of sequences that do not contain. of course XYZ There is no problem even count the number of sequence,

including the following XYZ The method of counting the number of sequences that do not contain explained.

From left 1 One by considering that a note of the full search to continue to determine the value of the sequence. In other words, the value of the place

you are looking now for a few rows XYZ Determined so that does not occur, the place we are looking now 1 Individual right to transfer, also repeated because

decide the value ....

How will you be able to memoization is this? First of all, XYZ = 575 At the time of, 1, 1, ..., 1 (1 But 17 In this case) is the most use pattern of the

value of the sequence. In other words, just before 16 It is sufficient to save the number of values.

This number of states N * Ten 16 become. It considerable improvement When compared to the full search, but do not fit in between, of course.

2
A little more thinking. For example, the value that appeared just before 5,5,5,5,7 There is no need to save it all as long as such. In other words,

the sum of the values that appeared just before 16 Only if you save yo Ikoto it is seen in the range which is below.

While this by the number of states is reduced, it will reduce how much? here, 1 = "1", 2 = "10", 3 = "100", 4 = "1000" ... When 0/1 Come to think

of it is converted to a string. In other words, the value that appeared just before 1, 2, 3 Datosuruto "110100" Be converted. The length of this string is

of value sum When equal. In other words, the sum of the previous value 16 It is because to save up to less than the length 16 of

0/1 It can be seen that corresponding to the character string. Therefore, the number of states N * 2 16 . In fact instead of stored as a

string, of course, 16 bit Save as an integer bit DP I do.

This allows the amount of calculation O (A * N * 2 X + Y + Z) To become ( A The type of value of the sequence, ie, Ten ) . This is in time at.

F Problem string love Iroha-chan


dp [i] [j]: = i Use a string of within-th, just the length of the j Dictionary order minimum of string at the time of the character

It is defined as. Except i + 1 It is filled with the character and subsequent string K - j Itoki be able to characters and may
not be defined. K - j To the of whether the character determination DP
It is easy to construct the table.
Space amount of calculation and a string with as it is O (NK 2) But, considering that to successfully hold the only optimal string, dp

[i] [0], dp [i] [1], ..., dp [i] [K] Each is "not defined" or "Of a common string pre fi x Become either ". In other words, each i Common

string with respect to CS i ( At most the length K) When, dp [i] [j] By but to have a determination of whether the flag has been

defined, the spatial calculations amount O (NK) It is reduced to.

each i The common string for, such as itself a dictionary order minimum dp [i] [j] It is considered only to hold the
determination flag.
dp During the update of the table, dp String of table Ya s i , Or it becomes necessary to perform a dictionary order string

comparison between the union of them to fast, but, LCP (Longest Common Pre fi x)

The process by obtaining a it can be seen that performed at high speed. All the string hash value of the management and
sub-string in a rolling hash table to be handled O ( 1) Leave to be required by, by performing a binary search for them, time
complexity O (logk) so LCP It can be obtained.
The time complexity of the whole O (NKlogK) , Space calculation amount O (NK) To become. 128 below 2 It devised a test case so

that it does not pass through a rolling hash number was used as a law to be. It is necessary to perform a division Therefore, division is

heavy because of its constant multiple, it is difficult through the solution using a rolling hash.

Therefore, considering that further improve the algorithm of the comparison section. Think what kind of a letter

or make a comparison of the column. Then

CS i What character or the beginning of the

CS i What character or the beginning of the + s i

3
It can be seen that comparing the only string to each other that. here, s i + CS i about Z - Algorithm
Encouraged to set up a table according to the, the comparison between these strings O (1) It is carried out in a can.

Therefore, the time complexity of the O (NK) To become. This is the assumed solution. Hereinafter, based on the above description dp It

shows an example of a table update. It is enumerated only defined values. Not mention the comparison part.

N = Five, K = 7 In the case, each s i It is made as follows.

s 1 = "Aaaaaa"

s 2 = "Abc"

s 3 = "Xxxx"

s 4 = "Ddd"

s 5 = "Abcd"

i = 0, 1, 2, 3, 4, 5 In DP Update of the table is as follows.

1. i = 0: dp [0] [0] = ""

2. i = 1: dp [1] [0] = ""

s 1 What later Using the use even length K = 7 A string from the fact that can not be achieved,
dp [1] [6] It is not defined.

3. i = 2: dp [2] [0] = "", dp [2] [3] = "abc"

Common string CS 2 = "Abc"

Four. i = 3: dp [3] [0] = "", dp [3] [3] = "abc", dp [3] [7] = "abcxxxx"

Common string CS 3 = "Abcxxxx"

dp [1] [4] = "xxxx" As well, because not become the common string of dictionary order minimum dp [ 1] [4]

It is not defined.

Five. i = 4: dp [4] [0] = "", dp [4] [3] = "abc", dp [4] [7] = "abcxxxx"

6. i = 5: dp [5] [0] = "", dp [5] [3] = "abc", dp [5] [7] = "abcabcd"

Common string CS 5 = "Abcabcd"

Four

Você também pode gostar