Statement Problem A: Bijection In this problem, you have to - - PowerPoint PPT Presentation

statement problem a bijection
SMART_READER_LITE
LIVE PREVIEW

Statement Problem A: Bijection In this problem, you have to - - PowerPoint PPT Presentation

Problem A: Bijection Statement Statement Problem A: Bijection In this problem, you have to establish a bijection between combinations and pairs of a regular bracket sequence and an integer. Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020


slide-1
SLIDE 1

Problem A: Bijection Statement

Statement Problem A: Bijection

In this problem, you have to establish a bijection between combinations and pairs of a regular bracket sequence and an integer.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 1 / 54

slide-2
SLIDE 2

Problem A: Bijection Details

Details

In this problem, you have to establish a bijection between combinations and pairs of a regular bracket sequence and an integer. Combinations, choose(4, 2) = 6: “RRUU”, “RURU”, “RUUR”, “URRU”, “URUR”, “UURR”.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 2 / 54

slide-3
SLIDE 3

Problem A: Bijection Details

Details

In this problem, you have to establish a bijection between combinations and pairs of a regular bracket sequence and an integer. Combinations, choose(4, 2) = 6: “RRUU”, “RURU”, “RUUR”, “URRU”, “URUR”, “UURR”. Regular bracket sequences, C2 = 2: “(())”, “()()”. Paired with an integer from {0, 1, 2}.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 2 / 54

slide-4
SLIDE 4

Problem A: Bijection Details

Details

In this problem, you have to establish a bijection between combinations and pairs of a regular bracket sequence and an integer. Combinations, choose(4, 2) = 6: “RRUU”, “RURU”, “RUUR”, “URRU”, “URUR”, “UURR”. Regular bracket sequences, C2 = 2: “(())”, “()()”. Paired with an integer from {0, 1, 2}. Combinations, choose(6, 3) = 20: “RRRUUU”, “RRURUU”, “RRUURU”, “RRUUUR”, “RURRUU”, “RURURU”, “RURUUR”, “RUURRU”, “RUURUR”, “RUUURR”, “URRRUU”, “URRURU”, “URRUUR”, “URURRU”, “URURUR”, “URUURR”, “UURRUU”, “UURURU”, “UURUUR”, “UUURRR”.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 2 / 54

slide-5
SLIDE 5

Problem A: Bijection Details

Details

In this problem, you have to establish a bijection between combinations and pairs of a regular bracket sequence and an integer. Combinations, choose(4, 2) = 6: “RRUU”, “RURU”, “RUUR”, “URRU”, “URUR”, “UURR”. Regular bracket sequences, C2 = 2: “(())”, “()()”. Paired with an integer from {0, 1, 2}. Combinations, choose(6, 3) = 20: “RRRUUU”, “RRURUU”, “RRUURU”, “RRUUUR”, “RURRUU”, “RURURU”, “RURUUR”, “RUURRU”, “RUURUR”, “RUUURR”, “URRRUU”, “URRURU”, “URRUUR”, “URURRU”, “URURUR”, “URUURR”, “UURRUU”, “UURURU”, “UURUUR”, “UUURRR”. Regular bracket sequences, C3 = 5: “((()))”, “(()())”, “(())()”, “()(())”, “()()()”. Paired with an integer from {0, 1, 2, 3}.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 2 / 54

slide-6
SLIDE 6

Problem A: Bijection Enumeration

Enumeration

Solution 1: just number the objects lexicographically.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 3 / 54

slide-7
SLIDE 7

Problem A: Bijection Enumeration

Enumeration

Solution 1: just number the objects lexicographically. Requirements: big integers combination ← → its number bracket sequence ← → its number Tedious but straightforward. Note: using a non-default language might speed up development.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 3 / 54

slide-8
SLIDE 8

Problem A: Bijection Proper Bijection

Proper Bijection

Solution 2: establish a natural bijection.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 4 / 54

slide-9
SLIDE 9

Problem A: Bijection Proper Bijection

Proper Bijection

Solution 2: establish a natural bijection. From path to bracket sequence. Write down the path, add an “U” at the end. Walk along the path and maintain the balance, where “R” adds +1 and “U” adds −1. Mark the first time when the balance was the least possible. The number k is the marked position minus one. The character before the marked position is “U”. Now loop the path. Starting from the marked position, take 2n characters. Transform “R” → “(” and “U” → “)”. This is guaranteed to be a regular bracket sequence.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 4 / 54

slide-10
SLIDE 10

Problem A: Bijection Proper Bijection

Proper Bijection

Solution 2: establish a natural bijection. From path to bracket sequence, example: “RUURUR”. Write down the path, add an “U” at the end: “RUURURU”. Walk along the path and maintain the balance, where “R” adds +1 and “U” adds −1: {+1, 0, −1, 0, −1, 0, −1}. Mark the first time when the balance was the least possible: “RUU|RURU”. The number k is the marked position minus one: k = 3 − 1 = 2. The character before the marked position is “U”. Now loop the path: “RUU|RURU

  • RUU|RURU
  • ...”.

Starting from the marked position, take 2n characters. Transform “R” → “(” and “U” → “)”. This is guaranteed to be a regular bracket sequence: “RURURU” → “()()()”.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 4 / 54

slide-11
SLIDE 11

Problem A: Bijection Proper Bijection

Proper Bijection

Solution 2: establish a natural bijection. From bracket sequence to path. Write down the sequence, add an “)” at the end. Now loop the sequence. Mark the position 2n − k. Starting from the marked position, take 2n characters. Transform “(” → “R” and “)” → “U”.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 4 / 54

slide-12
SLIDE 12

Problem A: Bijection Proper Bijection

Proper Bijection

Solution 2: establish a natural bijection. From bracket sequence to path, example: “()()()”, k = 2. Write down the sequence, add an “)” at the end: “()()())”. Now loop the sequence: “()()())

  • ()()())
  • ...”.

Mark the position 2n − k = 6 − 2 = 4: “()()|())

  • ()()())
  • ...”.

Starting from the marked position, take 2n characters. Transform “(” → “R” and “)” → “U”: “())()(” → “RUURUR”.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 4 / 54

slide-13
SLIDE 13

Problem A: Bijection Other Bijections

Other Bijections

Solution 3: other bijections are possible. For example, there is one based on exceedance, see here: https://en.wikipedia.org/wiki/Catalan_number#Third_proof.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 5 / 54

slide-14
SLIDE 14

Problem B: Rectangle Tree Statement

Statement Problem B: Rectangle Tree

In this problem, you have to rebuild a binary rooted tree of combinatorial rectangles so that it has logarithmic height compared to its size.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 6 / 54

slide-15
SLIDE 15

Problem B: Rectangle Tree Definitions

Definitions

In this problem, you have to rebuild a binary rooted tree of combinatorial rectangles so that it has logarithmic height compared to its size. Just like a rectangle consisting of board squares is (consecutive subset) × (consecutive subset), a combinatorial rectangle is (arbitrary subset) × (arbitrary subset).

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 7 / 54

slide-16
SLIDE 16

Problem B: Rectangle Tree Definitions

Definitions

In this problem, you have to rebuild a binary rooted tree of combinatorial rectangles so that it has logarithmic height compared to its size. Just like a rectangle consisting of board squares is (consecutive subset) × (consecutive subset), a combinatorial rectangle is (arbitrary subset) × (arbitrary subset). We have an n × n board consisting of colored squares. We also have a rooted tree of combinatorial rectangles. The root corresponds to the whole board. Each vertex either is a leaf or has two children. Children form a partition of the parent. For each leaf, the cells it contains are colored the same.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 7 / 54

slide-17
SLIDE 17

Problem B: Rectangle Tree Definitions

Definitions

In this problem, you have to rebuild a binary rooted tree of combinatorial rectangles so that it has logarithmic height compared to its size. Just like a rectangle consisting of board squares is (consecutive subset) × (consecutive subset), a combinatorial rectangle is (arbitrary subset) × (arbitrary subset). We have an n × n board consisting of colored squares. We also have a rooted tree of combinatorial rectangles. The root corresponds to the whole board. Each vertex either is a leaf or has two children. Children form a partition of the parent. For each leaf, the cells it contains are colored the same. Our task is to construct a tree with the same properties. Its size must not increase too much. Its height must be logarithmic in terms of size.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 7 / 54

slide-18
SLIDE 18

Problem B: Rectangle Tree Solution: Restriction

Solution: Restricton

Let us define restriction of a tree to a combinatorial rectangle A × B: Intersect all combinatorial rectangles in the tree with A × B. Remove all empty rectangles. If only one child is not empty, promote it to parent.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 8 / 54

slide-19
SLIDE 19

Problem B: Rectangle Tree Solution

Solution

Let U be the whole set [0, n − 1].

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 9 / 54

slide-20
SLIDE 20

Problem B: Rectangle Tree Solution

Solution

Let U be the whole set [0, n − 1]. Now, construct the new balanced tree as follows: Find the center C of the tree: its subtrees are of size S/3, but its

  • wn subtree is of size S/3.

Let the rectangle in C be A × B.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 9 / 54

slide-21
SLIDE 21

Problem B: Rectangle Tree Solution

Solution

Let U be the whole set [0, n − 1]. Now, construct the new balanced tree as follows: Find the center C of the tree: its subtrees are of size S/3, but its

  • wn subtree is of size S/3.

Let the rectangle in C be A × B. Then, the new root is U × U. The left child is A × U. Its children are A × B and A × (U \ B). The right child is (U \ A) × U.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 9 / 54

slide-22
SLIDE 22

Problem B: Rectangle Tree Solution

Solution

Let U be the whole set [0, n − 1]. Now, construct the new balanced tree as follows: Find the center C of the tree: its subtrees are of size S/3, but its

  • wn subtree is of size S/3.

Let the rectangle in C be A × B. Then, the new root is U × U. The left child is A × U. Its children are A × B and A × (U \ B). The right child is (U \ A) × U. For each of the three lower vertices, restrict the whole initial tree to its combinatorial rectangle, then construct a balanced subtree from it, with respective rectangles instead of U × U.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 9 / 54

slide-23
SLIDE 23

Problem B: Rectangle Tree Further Reading

Further Reading

Further reading: the topic can be googled as “balancing communication protocol”.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 10 / 54

slide-24
SLIDE 24

Problem C: Fastest Arrival Statement

Statement Problem C: Fastest Arrival

In this problem, you have to find an integer point in a disc that is closest to a given point on the plane.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 11 / 54

slide-25
SLIDE 25

Problem C: Fastest Arrival It Can’t Be Too Far

It Can’t Be Too Far

In this problem, you have to find an integer point in a disc that is closest to a given point on the plane. Degenerate case: the given point is in the disc already. Answer is 0.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 12 / 54

slide-26
SLIDE 26

Problem C: Fastest Arrival It Can’t Be Too Far

It Can’t Be Too Far

In this problem, you have to find an integer point in a disc that is closest to a given point on the plane. Degenerate case: the given point is in the disc already. Answer is 0. Let our point be P, and the disc have center C and radius r.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 12 / 54

slide-27
SLIDE 27

Problem C: Fastest Arrival It Can’t Be Too Far

It Can’t Be Too Far

In this problem, you have to find an integer point in a disc that is closest to a given point on the plane. Degenerate case: the given point is in the disc already. Answer is 0. Let our point be P, and the disc have center C and radius r. Find the point M where PC intersects the circle. Denote d = |PM|.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 12 / 54

slide-28
SLIDE 28

Problem C: Fastest Arrival It Can’t Be Too Far

It Can’t Be Too Far

In this problem, you have to find an integer point in a disc that is closest to a given point on the plane. Degenerate case: the given point is in the disc already. Answer is 0. Let our point be P, and the disc have center C and radius r. Find the point M where PC intersects the circle. Denote d = |PM|. Let us move along the circumference. How far can the desired integer point be?

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 12 / 54

slide-29
SLIDE 29

Problem C: Fastest Arrival It Can’t Be Too Far

It Can’t Be Too Far

In this problem, you have to find an integer point in a disc that is closest to a given point on the plane. Degenerate case: the given point is in the disc already. Answer is 0. Let our point be P, and the disc have center C and radius r. Find the point M where PC intersects the circle. Denote d = |PM|. Let us move along the circumference. How far can the desired integer point be? If we walk h units from M along the circumference, the distance from P will become more than √ d2 + h2.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 12 / 54

slide-30
SLIDE 30

Problem C: Fastest Arrival It Can’t Be Too Far

It Can’t Be Too Far

In this problem, you have to find an integer point in a disc that is closest to a given point on the plane. Degenerate case: the given point is in the disc already. Answer is 0. Let our point be P, and the disc have center C and radius r. Find the point M where PC intersects the circle. Denote d = |PM|. Let us move along the circumference. How far can the desired integer point be? If we walk h units from M along the circumference, the distance from P will become more than √ d2 + h2. When h 2 √ d + 1, that distance is at least d + 1. So we are farther from P already than some integer point in the circle which is closest to M.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 12 / 54

slide-31
SLIDE 31

Problem C: Fastest Arrival Illustration

Illustration

h h ≥ √ d + h ≥ √ d + h C P M d r

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 13 / 54

slide-32
SLIDE 32

Problem C: Fastest Arrival Walking Along the Circumference

Walking Along the Circumference

So, to be sure, we can just look at around 100 000 integer points close to circumference in each direction.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 14 / 54

slide-33
SLIDE 33

Problem C: Fastest Arrival Walking Along the Circumference

Walking Along the Circumference

So, to be sure, we can just look at around 100 000 integer points close to circumference in each direction. Classy: Bresenham algorithm.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 14 / 54

slide-34
SLIDE 34

Problem C: Fastest Arrival Walking Along the Circumference

Walking Along the Circumference

So, to be sure, we can just look at around 100 000 integer points close to circumference in each direction. Classy: Bresenham algorithm. Crude: for 100 000 adjacent x, find the best y; then, for 100 000 adjacent y, find the best x.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 14 / 54

slide-35
SLIDE 35

Problem C: Fastest Arrival Walking Along the Circumference

Walking Along the Circumference

So, to be sure, we can just look at around 100 000 integer points close to circumference in each direction. Classy: Bresenham algorithm. Crude: for 100 000 adjacent x, find the best y; then, for 100 000 adjacent y, find the best x. More crude: when searching for the “best” y, consider a couple adjacent y, and for each of them, check the distance to the circle

  • center. Same for the “best” x.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 14 / 54

slide-36
SLIDE 36

Problem C: Fastest Arrival Walking Along the Circumference

Walking Along the Circumference

So, to be sure, we can just look at around 100 000 integer points close to circumference in each direction. Classy: Bresenham algorithm. Crude: for 100 000 adjacent x, find the best y; then, for 100 000 adjacent y, find the best x. More crude: when searching for the “best” y, consider a couple adjacent y, and for each of them, check the distance to the circle

  • center. Same for the “best” x.

So, why is the success rate for this problem so low?

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 14 / 54

slide-37
SLIDE 37

Problem C: Fastest Arrival Walking Along the Circumference

Walking Along the Circumference

So, to be sure, we can just look at around 100 000 integer points close to circumference in each direction. Classy: Bresenham algorithm. Crude: for 100 000 adjacent x, find the best y; then, for 100 000 adjacent y, find the best x. More crude: when searching for the “best” y, consider a couple adjacent y, and for each of them, check the distance to the circle

  • center. Same for the “best” x.

So, why is the success rate for this problem so low? Not trying far enough: in the tests, the optimal point can be more than 10 000 units far from M.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 14 / 54

slide-38
SLIDE 38

Problem C: Fastest Arrival Walking Along the Circumference

Walking Along the Circumference

So, to be sure, we can just look at around 100 000 integer points close to circumference in each direction. Classy: Bresenham algorithm. Crude: for 100 000 adjacent x, find the best y; then, for 100 000 adjacent y, find the best x. More crude: when searching for the “best” y, consider a couple adjacent y, and for each of them, check the distance to the circle

  • center. Same for the “best” x.

So, why is the success rate for this problem so low? Not trying far enough: in the tests, the optimal point can be more than 10 000 units far from M. In a crude solution, neglect having both x and y parts.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 14 / 54

slide-39
SLIDE 39

Problem C: Fastest Arrival Walking Along the Circumference

Walking Along the Circumference

So, to be sure, we can just look at around 100 000 integer points close to circumference in each direction. Classy: Bresenham algorithm. Crude: for 100 000 adjacent x, find the best y; then, for 100 000 adjacent y, find the best x. More crude: when searching for the “best” y, consider a couple adjacent y, and for each of them, check the distance to the circle

  • center. Same for the “best” x.

So, why is the success rate for this problem so low? Not trying far enough: in the tests, the optimal point can be more than 10 000 units far from M. In a crude solution, neglect having both x and y parts. Overflows or precision errors.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 14 / 54

slide-40
SLIDE 40

Problem C: Fastest Arrival Walking Along the Circumference

Walking Along the Circumference

So, to be sure, we can just look at around 100 000 integer points close to circumference in each direction. Classy: Bresenham algorithm. Crude: for 100 000 adjacent x, find the best y; then, for 100 000 adjacent y, find the best x. More crude: when searching for the “best” y, consider a couple adjacent y, and for each of them, check the distance to the circle

  • center. Same for the “best” x.

So, why is the success rate for this problem so low? Not trying far enough: in the tests, the optimal point can be more than 10 000 units far from M. In a crude solution, neglect having both x and y parts. Overflows or precision errors. ...tell us about your case!

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 14 / 54

slide-41
SLIDE 41

Problem D: Lost in Transfer Statement

Statement Problem D: Lost in Transfer

In this problem, you have to recover the numbers being transmitted, even in the unfortunate case one of them is lost.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 15 / 54

slide-42
SLIDE 42

Problem D: Lost in Transfer Details

Details

In this problem, you have to recover the numbers being transmitted, even in the unfortunate case one of them is lost. You are given a set of 20 to 100 distinct integers from 1 to 500.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 16 / 54

slide-43
SLIDE 43

Problem D: Lost in Transfer Details

Details

In this problem, you have to recover the numbers being transmitted, even in the unfortunate case one of them is lost. You are given a set of 20 to 100 distinct integers from 1 to 500. You have to transmit each of them exactly once.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 16 / 54

slide-44
SLIDE 44

Problem D: Lost in Transfer Details

Details

In this problem, you have to recover the numbers being transmitted, even in the unfortunate case one of them is lost. You are given a set of 20 to 100 distinct integers from 1 to 500. You have to transmit each of them exactly once. You control the order of transmission.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 16 / 54

slide-45
SLIDE 45

Problem D: Lost in Transfer Details

Details

In this problem, you have to recover the numbers being transmitted, even in the unfortunate case one of them is lost. You are given a set of 20 to 100 distinct integers from 1 to 500. You have to transmit each of them exactly once. You control the order of transmission. You then receive the same numbers in the same order, but one of them may be missing.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 16 / 54

slide-46
SLIDE 46

Problem D: Lost in Transfer Details

Details

In this problem, you have to recover the numbers being transmitted, even in the unfortunate case one of them is lost. You are given a set of 20 to 100 distinct integers from 1 to 500. You have to transmit each of them exactly once. You control the order of transmission. You then receive the same numbers in the same order, but one of them may be missing. Nevertheless, you have to recover the original set (order is irrelevant).

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 16 / 54

slide-47
SLIDE 47

Problem D: Lost in Transfer Order Does Matter

Order Does Matter

Naturally, you will have to use the order to transfer additional information.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 17 / 54

slide-48
SLIDE 48

Problem D: Lost in Transfer Order Does Matter

Order Does Matter

Naturally, you will have to use the order to transfer additional information. Calculate some redundant statistic of all the numbers in the set: xor-sum, or sum modulo 501, or...

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 17 / 54

slide-49
SLIDE 49

Problem D: Lost in Transfer Order Does Matter

Order Does Matter

Naturally, you will have to use the order to transfer additional information. Calculate some redundant statistic of all the numbers in the set: xor-sum, or sum modulo 501, or... In the first run, encode this value using the order of elements.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 17 / 54

slide-50
SLIDE 50

Problem D: Lost in Transfer Order Does Matter

Order Does Matter

Naturally, you will have to use the order to transfer additional information. Calculate some redundant statistic of all the numbers in the set: xor-sum, or sum modulo 501, or... In the first run, encode this value using the order of elements. In the second run, calculate the same statistic for the received set, extract the original value from the order, and compare them.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 17 / 54

slide-51
SLIDE 51

Problem D: Lost in Transfer Order Does Matter

Order Does Matter

Naturally, you will have to use the order to transfer additional information. Calculate some redundant statistic of all the numbers in the set: xor-sum, or sum modulo 501, or... In the first run, encode this value using the order of elements. In the second run, calculate the same statistic for the received set, extract the original value from the order, and compare them. If they are equal, no element is missing.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 17 / 54

slide-52
SLIDE 52

Problem D: Lost in Transfer Order Does Matter

Order Does Matter

Naturally, you will have to use the order to transfer additional information. Calculate some redundant statistic of all the numbers in the set: xor-sum, or sum modulo 501, or... In the first run, encode this value using the order of elements. In the second run, calculate the same statistic for the received set, extract the original value from the order, and compare them. If they are equal, no element is missing. Otherwise, use the two statistics to determine the missing element.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 17 / 54

slide-53
SLIDE 53

Problem D: Lost in Transfer Bitwise Solution

Bitwise Solution

Solution 1: encode individual bits of the statistic.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 18 / 54

slide-54
SLIDE 54

Problem D: Lost in Transfer Bitwise Solution

Bitwise Solution

Solution 1: encode individual bits of the statistic. Sort the elements of the set.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 18 / 54

slide-55
SLIDE 55

Problem D: Lost in Transfer Bitwise Solution

Bitwise Solution

Solution 1: encode individual bits of the statistic. Sort the elements of the set. Write each bit twice.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 18 / 54

slide-56
SLIDE 56

Problem D: Lost in Transfer Bitwise Solution

Bitwise Solution

Solution 1: encode individual bits of the statistic. Sort the elements of the set. Write each bit twice. To encode a 1 bit, print the maximal remaining element two times.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 18 / 54

slide-57
SLIDE 57

Problem D: Lost in Transfer Bitwise Solution

Bitwise Solution

Solution 1: encode individual bits of the statistic. Sort the elements of the set. Write each bit twice. To encode a 1 bit, print the maximal remaining element two times. To encode a 0 bit, print the minimal remaining element two times.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 18 / 54

slide-58
SLIDE 58

Problem D: Lost in Transfer Bitwise Solution

Bitwise Solution

Solution 1: encode individual bits of the statistic. Sort the elements of the set. Write each bit twice. To encode a 1 bit, print the maximal remaining element two times. To encode a 0 bit, print the minimal remaining element two times. Proceed until there are no more elements left.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 18 / 54

slide-59
SLIDE 59

Problem D: Lost in Transfer Bitwise Solution

Bitwise Solution

Solution 1: encode individual bits of the statistic. Sort the elements of the set. Write each bit twice. To encode a 1 bit, print the maximal remaining element two times. To encode a 0 bit, print the minimal remaining element two times. Proceed until there are no more elements left. Example: to encode bits 10110... (followed by zeroes) with the numbers 1, 2, . . ., 20, print: 20, 19

for1

, 1, 2

  • for0

, 18, 17

for1

, 16, 15

for1

, 3, 4

  • for0

, . . . , 13, 14

for0

.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 18 / 54

slide-60
SLIDE 60

Problem D: Lost in Transfer Bitwise Solution

Bitwise Solution

Solution 1: encode individual bits of the statistic. Decoding: consider the relations between adjacent elements.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 18 / 54

slide-61
SLIDE 61

Problem D: Lost in Transfer Bitwise Solution

Bitwise Solution

Solution 1: encode individual bits of the statistic. Decoding: consider the relations between adjacent elements. Here, we have: 20 > 19 > 1 < 2 < 18 > 17 > 16 > 15 > 3 < 4 < . . . < 13 < 14.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 18 / 54

slide-62
SLIDE 62

Problem D: Lost in Transfer Bitwise Solution

Bitwise Solution

Solution 1: encode individual bits of the statistic. Decoding: consider the relations between adjacent elements. Here, we have: 20 > 19 > 1 < 2 < 18 > 17 > 16 > 15 > 3 < 4 < . . . < 13 < 14. If no element is missing, inequalities come in pairs: >><<>>>><<<<...<<.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 18 / 54

slide-63
SLIDE 63

Problem D: Lost in Transfer Bitwise Solution

Bitwise Solution

Solution 1: encode individual bits of the statistic. Decoding: consider the relations between adjacent elements. Here, we have: 20 > 19 > 1 < 2 < 18 > 17 > 16 > 15 > 3 < 4 < . . . < 13 < 14. If no element is missing, inequalities come in pairs: >><<>>>><<<<...<<. If an element is missing, some run of equal signs will have odd length.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 18 / 54

slide-64
SLIDE 64

Problem D: Lost in Transfer Bitwise Solution

Bitwise Solution

Solution 1: encode individual bits of the statistic. Decoding: consider the relations between adjacent elements. Here, we have: 20 > 19 > 1 < 2 < 18 > 17 > 16 > 15 > 3 < 4 < . . . < 13 < 14. If no element is missing, inequalities come in pairs: >><<>>>><<<<...<<. If an element is missing, some run of equal signs will have odd length. For example, if 17 is missing, we still have: 20 > 19 > 1 < 2 < 18 > 16 > 15 > 3 < 4 < . . . < 13 < 14.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 18 / 54

slide-65
SLIDE 65

Problem D: Lost in Transfer Bitwise Solution

Bitwise Solution

Solution 1: encode individual bits of the statistic. Decoding: consider the relations between adjacent elements. Here, we have: 20 > 19 > 1 < 2 < 18 > 17 > 16 > 15 > 3 < 4 < . . . < 13 < 14. If no element is missing, inequalities come in pairs: >><<>>>><<<<...<<. If an element is missing, some run of equal signs will have odd length. For example, if 17 is missing, we still have: 20 > 19 > 1 < 2 < 18 > 16 > 15 > 3 < 4 < . . . < 13 < 14. The way to decode it: take the next sign and transform > → 1 and < → 0; remove the sign from consideration; if the sign after it is the same, remove it too.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 18 / 54

slide-66
SLIDE 66

Problem D: Lost in Transfer Randomized Solution

Randomized Solution

Solution 2: encode each possible value with a random permutation.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 19 / 54

slide-67
SLIDE 67

Problem D: Lost in Transfer Randomized Solution

Randomized Solution

Solution 2: encode each possible value with a random permutation. Assign a pseudorandom permutation p(i) (same each run) of length 20 to each possible value i (perhaps values can range from 0 to 511).

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 19 / 54

slide-68
SLIDE 68

Problem D: Lost in Transfer Randomized Solution

Randomized Solution

Solution 2: encode each possible value with a random permutation. Assign a pseudorandom permutation p(i) (same each run) of length 20 to each possible value i (perhaps values can range from 0 to 511). In the first run, reorder the first 20 elements of the set according to the permutation p(x) corresponding to the value x you want to transfer.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 19 / 54

slide-69
SLIDE 69

Problem D: Lost in Transfer Randomized Solution

Randomized Solution

Solution 2: encode each possible value with a random permutation. Assign a pseudorandom permutation p(i) (same each run) of length 20 to each possible value i (perhaps values can range from 0 to 511). In the first run, reorder the first 20 elements of the set according to the permutation p(x) corresponding to the value x you want to transfer. In the second run, look at the permutation q of the first 19 elements.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 19 / 54

slide-70
SLIDE 70

Problem D: Lost in Transfer Randomized Solution

Randomized Solution

Solution 2: encode each possible value with a random permutation. Assign a pseudorandom permutation p(i) (same each run) of length 20 to each possible value i (perhaps values can range from 0 to 511). In the first run, reorder the first 20 elements of the set according to the permutation p(x) corresponding to the value x you want to transfer. In the second run, look at the permutation q of the first 19 elements. With high probability, there is only one possible y such that permuting according to p(y) and then dropping one of the elements could have produced q.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 19 / 54

slide-71
SLIDE 71

Problem D: Lost in Transfer Randomized Solution

Randomized Solution

Solution 2: encode each possible value with a random permutation. Assign a pseudorandom permutation p(i) (same each run) of length 20 to each possible value i (perhaps values can range from 0 to 511). In the first run, reorder the first 20 elements of the set according to the permutation p(x) corresponding to the value x you want to transfer. In the second run, look at the permutation q of the first 19 elements. With high probability, there is only one possible y such that permuting according to p(y) and then dropping one of the elements could have produced q. Just check all 512 · 20 possibilities to be sure!

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 19 / 54

slide-72
SLIDE 72

Problem D: Lost in Transfer Randomized Solution

Randomized Solution

Solution 2: encode each possible value with a random permutation. Assign a pseudorandom permutation p(i) (same each run) of length 20 to each possible value i (perhaps values can range from 0 to 511). In the first run, reorder the first 20 elements of the set according to the permutation p(x) corresponding to the value x you want to transfer. In the second run, look at the permutation q of the first 19 elements. With high probability, there is only one possible y such that permuting according to p(y) and then dropping one of the elements could have produced q. Just check all 512 · 20 possibilities to be sure! Then y is the value x you wanted to transfer.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 19 / 54

slide-73
SLIDE 73

Problem E: Maze with a Hint Statement

Statement Problem E: Maze with a Hint

In this problem, you have to first look at a maze and write a short hint, and then look at the hint and interactively solve the maze.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 20 / 54

slide-74
SLIDE 74

Problem E: Maze with a Hint Solving the Maze

Solving the Maze

In this problem, you have to first look at a maze and write a short hint, and then look at the hint and interactively solve the maze. How do we solve a maze with full information?

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 21 / 54

slide-75
SLIDE 75

Problem E: Maze with a Hint Solving the Maze

Solving the Maze

In this problem, you have to first look at a maze and write a short hint, and then look at the hint and interactively solve the maze. How do we solve a maze with full information?

Breadth-first search.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 21 / 54

slide-76
SLIDE 76

Problem E: Maze with a Hint Solving the Maze

Solving the Maze

In this problem, you have to first look at a maze and write a short hint, and then look at the hint and interactively solve the maze. How do we solve a maze with full information?

Breadth-first search.

How do we solve a maze when we only see the current square?

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 21 / 54

slide-77
SLIDE 77

Problem E: Maze with a Hint Solving the Maze

Solving the Maze

In this problem, you have to first look at a maze and write a short hint, and then look at the hint and interactively solve the maze. How do we solve a maze with full information?

Breadth-first search.

How do we solve a maze when we only see the current square?

Right-hand rule: move along the maze so that you always keep touching the wall with your right hand.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 21 / 54

slide-78
SLIDE 78

Problem E: Maze with a Hint Solving the Maze

Solving the Maze

In this problem, you have to first look at a maze and write a short hint, and then look at the hint and interactively solve the maze. How do we solve a maze with full information?

Breadth-first search.

How do we solve a maze when we only see the current square?

Right-hand rule: move along the maze so that you always keep touching the wall with your right hand. Heuristic: maintain the map of visited squares, and move to the “best” unknown square, in some sense (closest to us, most probably on the right path, ...).

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 21 / 54

slide-79
SLIDE 79

Problem E: Maze with a Hint Bumping into Constraints

Bumping into Constraints

Maze is up to 200 × 200 squares. Hint is up to 1000 bits. Path is up to 6000 steps.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 22 / 54

slide-80
SLIDE 80

Problem E: Maze with a Hint Bumping into Constraints

Bumping into Constraints

Maze is up to 200 × 200 squares. Hint is up to 1000 bits. Path is up to 6000 steps. If we do a breadth-first search, we find the shortest path. In the tests, it is up to 1394 steps long. Remember that you have half the tests, so you can check that without writing a test generator!

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 22 / 54

slide-81
SLIDE 81

Problem E: Maze with a Hint Bumping into Constraints

Bumping into Constraints

Maze is up to 200 × 200 squares. Hint is up to 1000 bits. Path is up to 6000 steps. If we do a breadth-first search, we find the shortest path. In the tests, it is up to 1394 steps long. Remember that you have half the tests, so you can check that without writing a test generator! If we solve using the right-hand rule, the path will contain half the squares on average.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 22 / 54

slide-82
SLIDE 82

Problem E: Maze with a Hint Packing the Optimal Path

Packing the Optimal Path

Solution 1: just encode the shortest path into 1000 bits we have.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 23 / 54

slide-83
SLIDE 83

Problem E: Maze with a Hint Packing the Optimal Path

Packing the Optimal Path

Solution 1: just encode the shortest path into 1000 bits we have. On each step, we have 1, 2, or 3 possible paths forward.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 23 / 54

slide-84
SLIDE 84

Problem E: Maze with a Hint Packing the Optimal Path

Packing the Optimal Path

Solution 1: just encode the shortest path into 1000 bits we have. On each step, we have 1, 2, or 3 possible paths forward. If there is a single path forward, no hint is needed.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 23 / 54

slide-85
SLIDE 85

Problem E: Maze with a Hint Packing the Optimal Path

Packing the Optimal Path

Solution 1: just encode the shortest path into 1000 bits we have. On each step, we have 1, 2, or 3 possible paths forward. If there is a single path forward, no hint is needed. Baseline: Remember each remaining step using two bits. Hint length: 1530, still too long.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 23 / 54

slide-86
SLIDE 86

Problem E: Maze with a Hint Packing the Optimal Path

Packing the Optimal Path

Solution 1: just encode the shortest path into 1000 bits we have. On each step, we have 1, 2, or 3 possible paths forward. If there is a single path forward, no hint is needed. Baseline: Remember each remaining step using two bits. Hint length: 1530, still too long. Improved: Use one bit when there are 2 possible paths, two bits when there are 3. Hint length: 910, OK.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 23 / 54

slide-87
SLIDE 87

Problem E: Maze with a Hint Packing the Optimal Path

Packing the Optimal Path

Solution 1: just encode the shortest path into 1000 bits we have. On each step, we have 1, 2, or 3 possible paths forward. If there is a single path forward, no hint is needed. Baseline: Remember each remaining step using two bits. Hint length: 1530, still too long. Improved: Use one bit when there are 2 possible paths, two bits when there are 3. Hint length: 910, OK. Big-integer: Use one bit when there are 2 possible paths, one ternary digit when there are 3. Pack all that into a big integer, and print it in binary as a hint. Hint length: 850, OK.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 23 / 54

slide-88
SLIDE 88

Problem E: Maze with a Hint Remembering Critical Crossroads

Remembering Critical Crossroads

Solution 2: walk using the right-hand rule, but take a hint at 4-crossroads.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 24 / 54

slide-89
SLIDE 89

Problem E: Maze with a Hint Remembering Critical Crossroads

Remembering Critical Crossroads

Solution 2: walk using the right-hand rule, but take a hint at 4-crossroads. A 4-crossroads is a square with all 4 paths open.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 24 / 54

slide-90
SLIDE 90

Problem E: Maze with a Hint Remembering Critical Crossroads

Remembering Critical Crossroads

Solution 2: walk using the right-hand rule, but take a hint at 4-crossroads. A 4-crossroads is a square with all 4 paths open. There will be only few 4-crossroads along our path.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 24 / 54

slide-91
SLIDE 91

Problem E: Maze with a Hint Remembering Critical Crossroads

Remembering Critical Crossroads

Solution 2: walk using the right-hand rule, but take a hint at 4-crossroads. A 4-crossroads is a square with all 4 paths open. There will be only few 4-crossroads along our path. On each of them, remember the right direction (found by breadth-first search) using two bits.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 24 / 54

slide-92
SLIDE 92

Problem E: Maze with a Hint Remembering Critical Crossroads

Remembering Critical Crossroads

Solution 2: walk using the right-hand rule, but take a hint at 4-crossroads. A 4-crossroads is a square with all 4 paths open. There will be only few 4-crossroads along our path. On each of them, remember the right direction (found by breadth-first search) using two bits. Right-hand rule: hint length 430, path length 5530.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 24 / 54

slide-93
SLIDE 93

Problem E: Maze with a Hint Remembering Critical Crossroads

Remembering Critical Crossroads

Solution 2: walk using the right-hand rule, but take a hint at 4-crossroads. A 4-crossroads is a square with all 4 paths open. There will be only few 4-crossroads along our path. On each of them, remember the right direction (found by breadth-first search) using two bits. Right-hand rule: hint length 430, path length 5530. Left-hand rule: hint length 406, path length 4858.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 24 / 54

slide-94
SLIDE 94

Problem E: Maze with a Hint Other Solutions Are Possible

Other Solutions Are Possible

Solution 3: (insert your solution here).

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 25 / 54

slide-95
SLIDE 95

Problem F: Maharajas Are Going Home Statement

Statement Problem F: Maharajas Are Going Home

In this problem, you have to find a winning move for a disjunctive sum of games, or determine that there is none.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 26 / 54

slide-96
SLIDE 96

Problem F: Maharajas Are Going Home Details

Details

In this problem, you have to find a winning move for a disjunctive sum of games, or determine that there is none. A maharaja has all the moves available to chess queen and chess knight. In this problem, it can move only towards the origin, and multiple maharajas can occupy the same square.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 27 / 54

slide-97
SLIDE 97

Problem F: Maharajas Are Going Home Details

Details

In this problem, you have to find a winning move for a disjunctive sum of games, or determine that there is none. A maharaja has all the moves available to chess queen and chess knight. In this problem, it can move only towards the origin, and multiple maharajas can occupy the same square. You are given the initial positions of maharajas on a board which is infinite in positive directions.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 27 / 54

slide-98
SLIDE 98

Problem F: Maharajas Are Going Home Details

Details

In this problem, you have to find a winning move for a disjunctive sum of games, or determine that there is none. A maharaja has all the moves available to chess queen and chess knight. In this problem, it can move only towards the origin, and multiple maharajas can occupy the same square. You are given the initial positions of maharajas on a board which is infinite in positive directions. Two players move in turns, the player who can not make a move loses.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 27 / 54

slide-99
SLIDE 99

Problem F: Maharajas Are Going Home Details

Details

In this problem, you have to find a winning move for a disjunctive sum of games, or determine that there is none. A maharaja has all the moves available to chess queen and chess knight. In this problem, it can move only towards the origin, and multiple maharajas can occupy the same square. You are given the initial positions of maharajas on a board which is infinite in positive directions. Two players move in turns, the player who can not make a move loses. Find the lexicographically smallest winning move in the following form: number of maharaja, destination row, destination column.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 27 / 54

slide-100
SLIDE 100

Problem F: Maharajas Are Going Home Details

Details

In this problem, you have to find a winning move for a disjunctive sum of games, or determine that there is none. A maharaja has all the moves available to chess queen and chess knight. In this problem, it can move only towards the origin, and multiple maharajas can occupy the same square. You are given the initial positions of maharajas on a board which is infinite in positive directions. Two players move in turns, the player who can not make a move loses. Find the lexicographically smallest winning move in the following form: number of maharaja, destination row, destination column. Or determine there is no such move.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 27 / 54

slide-101
SLIDE 101

Problem F: Maharajas Are Going Home Grundy Numbers

Grundy Numbers

The problem boils down to finding Grundy value for every possible position

  • f a maharaja. Then, compute the xor-sum of the given maharajas. If it is

zero, there is no winning move. Otherwise, iterate over all possible moves and find the lexicographically first move that makes the xor-sum zero.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 28 / 54

slide-102
SLIDE 102

Problem F: Maharajas Are Going Home Grundy Numbers

Grundy Numbers

The problem boils down to finding Grundy value for every possible position

  • f a maharaja. Then, compute the xor-sum of the given maharajas. If it is

zero, there is no winning move. Otherwise, iterate over all possible moves and find the lexicographically first move that makes the xor-sum zero. Straightforward solution, by definition: for every square, construct a set of Grundy values after all possible moves, and find its minimal excludant.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 28 / 54

slide-103
SLIDE 103

Problem F: Maharajas Are Going Home Bitsets

Bitsets

How to find Grundy values fast?

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 29 / 54

slide-104
SLIDE 104

Problem F: Maharajas Are Going Home Bitsets

Bitsets

How to find Grundy values fast? For each square, the set consists of the values in its row, its column, its diagonal, and the two knight’s moves.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 29 / 54

slide-105
SLIDE 105

Problem F: Maharajas Are Going Home Bitsets

Bitsets

How to find Grundy values fast? For each square, the set consists of the values in its row, its column, its diagonal, and the two knight’s moves. Maintain the sets for each row, column, and diagonal. When we learn the value in a new square, update these sets.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 29 / 54

slide-106
SLIDE 106

Problem F: Maharajas Are Going Home Bitsets

Bitsets

How to find Grundy values fast? For each square, the set consists of the values in its row, its column, its diagonal, and the two knight’s moves. Maintain the sets for each row, column, and diagonal. When we learn the value in a new square, update these sets. For each square, the slowest operation is to find the union of the respective three sets, then find its minimal excludant.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 29 / 54

slide-107
SLIDE 107

Problem F: Maharajas Are Going Home Bitsets

Bitsets

How to find Grundy values fast? For each square, the set consists of the values in its row, its column, its diagonal, and the two knight’s moves. Maintain the sets for each row, column, and diagonal. When we learn the value in a new square, update these sets. For each square, the slowest operation is to find the union of the respective three sets, then find its minimal excludant. Speedup: store sets as bitsets. Then we effectively operate on 32 or 64 elements at once.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 29 / 54

slide-108
SLIDE 108

Problem F: Maharajas Are Going Home Optimizations

Optimizations

What if it is still too slow?

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 30 / 54

slide-109
SLIDE 109

Problem F: Maharajas Are Going Home Optimizations

Optimizations

What if it is still too slow? Symmetry: rows have the same sets as columns, lower diagonals have the same sets as upper diagonals. The table of Grundy values is also symmetric.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 30 / 54

slide-110
SLIDE 110

Problem F: Maharajas Are Going Home Optimizations

Optimizations

What if it is still too slow? Symmetry: rows have the same sets as columns, lower diagonals have the same sets as upper diagonals. The table of Grundy values is also symmetric. When looking for minimal excludant in a row, start with the previous value for that row, instead of starting from 0 every time.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 30 / 54

slide-111
SLIDE 111

Problem F: Maharajas Are Going Home Optimizations

Optimizations

What if it is still too slow? Symmetry: rows have the same sets as columns, lower diagonals have the same sets as upper diagonals. The table of Grundy values is also symmetric. When looking for minimal excludant in a row, start with the previous value for that row, instead of starting from 0 every time. When looking for the best move, consider only possible moves, instead

  • f iterating over the whole board.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 30 / 54

slide-112
SLIDE 112

Problem G: Ook Statement

Statement Problem G: Ook

In this problem, you have to cut pieces from a string, match them to a pattern, and maximize the sum of results.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 31 / 54

slide-113
SLIDE 113

Problem G: Ook Details

Details

In this problem, you have to cut pieces from a string, match them to a pattern, and maximize the sum of results. Example: o = 3, k = 5, S = ookkoko, P = ok?.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 32 / 54

slide-114
SLIDE 114

Problem G: Ook Details

Details

In this problem, you have to cut pieces from a string, match them to a pattern, and maximize the sum of results. Example: o = 3, k = 5, S = ookkoko, P = ok?.

  • okkoko
  • k?

miss 1, value 3 + 3 + 5 = 11, result 11/21 = 5.

  • k?

miss 0, value 3 + 5 + 5 = 13, result 13/20 = 13.

  • k?

miss 1, value 5 + 5 + 3 = 13, result 13/21 = 6.

  • k?

miss 2, value 5 + 3 + 5 = 13, result 13/22 = 3.

  • k? miss 0, value 3 + 5 + 3 = 11, result 11/20 = 11.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 32 / 54

slide-115
SLIDE 115

Problem G: Ook Details

Details

In this problem, you have to cut pieces from a string, match them to a pattern, and maximize the sum of results. Example: o = 3, k = 5, S = ookkoko, P = ok?.

  • okkoko
  • k?

miss 1, value 3 + 3 + 5 = 11, result 11/21 = 5.

  • k?

miss 0, value 3 + 5 + 5 = 13, result 13/20 = 13.

  • k?

miss 1, value 5 + 5 + 3 = 13, result 13/21 = 6.

  • k?

miss 2, value 5 + 3 + 5 = 13, result 13/22 = 3.

  • k? miss 0, value 3 + 5 + 3 = 11, result 11/20 = 11.

The best solution is to cut like this: o okk

  • ko

. This gives a total score of 13 + 11 = 24.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 32 / 54

slide-116
SLIDE 116

Problem G: Ook Convolution

Convolution

For each starting position i for the pattern in string S, the number of mismatches is the sum of two values, Ai + Bi: Ai is the number of k in the pattern when there is o in the string. Bi is the number of o in the pattern when there is k in the string.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 33 / 54

slide-117
SLIDE 117

Problem G: Ook Convolution

Convolution

For each starting position i for the pattern in string S, the number of mismatches is the sum of two values, Ai + Bi: Ai is the number of k in the pattern when there is o in the string. Bi is the number of o in the pattern when there is k in the string. Let us calculate all numbers Ai (and then Bi similarly).

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 33 / 54

slide-118
SLIDE 118

Problem G: Ook Convolution

Convolution

For each starting position i for the pattern in string S, the number of mismatches is the sum of two values, Ai + Bi: Ai is the number of k in the pattern when there is o in the string. Bi is the number of o in the pattern when there is k in the string. Let us calculate all numbers Ai (and then Bi similarly). Consider a binary sequence “there is o in this position of S” and a binary sequence “there is k in this position of P”. Find their convolution using Fast Fourier Transform: reverse the latter, FFT both, multiply, inverse FFT the result. The resulting values are the numbers Ai.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 33 / 54

slide-119
SLIDE 119

Problem G: Ook Dynamic Programming

Dynamic Programming

Let f (i) be the best result for string S1S2 . . . Si.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 34 / 54

slide-120
SLIDE 120

Problem G: Ook Dynamic Programming

Dynamic Programming

Let f (i) be the best result for string S1S2 . . . Si. Then f (i) = max{f (i − 1), f (i − |P|) + v(i − |P|)}. Here, v(j) is the value obtained by matching the pattern starting at position j of the string.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 34 / 54

slide-121
SLIDE 121

Problem H: Pi Approximation Statement

Statement Problem H: Pi Approximation

In this problem, you have to find the best approximation for π obtained by calculating the number of Pythagorean triples from integers 1, 2, . . . , n.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 35 / 54

slide-122
SLIDE 122

Problem H: Pi Approximation General Outline

General Outline

In this problem, you have to find the best approximation for π obtained by calculating the number of Pythagorean triples from integers 1, 2, . . . , n. Turns out we can just generate primitive Pythagorean triples fast enough.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 36 / 54

slide-123
SLIDE 123

Problem H: Pi Approximation General Outline

General Outline

In this problem, you have to find the best approximation for π obtained by calculating the number of Pythagorean triples from integers 1, 2, . . . , n. Turns out we can just generate primitive Pythagorean triples fast enough. For example, there’s Euclid’s formula: for 0 < n < m where n and m are coprime and of different parity, a = m2 − n2, b = 2mn, and c = m2 + n2 are a unique primitive Pythagorean triple.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 36 / 54

slide-124
SLIDE 124

Problem H: Pi Approximation General Outline

General Outline

In this problem, you have to find the best approximation for π obtained by calculating the number of Pythagorean triples from integers 1, 2, . . . , n. Turns out we can just generate primitive Pythagorean triples fast enough. For example, there’s Euclid’s formula: for 0 < n < m where n and m are coprime and of different parity, a = m2 − n2, b = 2mn, and c = m2 + n2 are a unique primitive Pythagorean triple. It turns out that the number of such triples with each possible sum is small enough (as hinted by the example), so we can store these quantities in a straightforward way, in a 200MB array of bytes.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 36 / 54

slide-125
SLIDE 125

Problem H: Pi Approximation General Outline

General Outline

In this problem, you have to find the best approximation for π obtained by calculating the number of Pythagorean triples from integers 1, 2, . . . , n. Turns out we can just generate primitive Pythagorean triples fast enough. For example, there’s Euclid’s formula: for 0 < n < m where n and m are coprime and of different parity, a = m2 − n2, b = 2mn, and c = m2 + n2 are a unique primitive Pythagorean triple. It turns out that the number of such triples with each possible sum is small enough (as hinted by the example), so we can store these quantities in a straightforward way, in a 200MB array of bytes. To speed things up, process all queries at once.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 36 / 54

slide-126
SLIDE 126

Problem I: Partition of Queries Statement

Statement Problem I: Partition of Queries

In this problem, you have to decide when to rebuild a data structure so that the total time for processing the given queries is minimized.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 37 / 54

slide-127
SLIDE 127

Problem I: Partition of Queries Details

Details

In this problem, you have to decide when to rebuild a data structure so that the total time for processing the given queries is minimized. Example: queries are “++??+?”, rebuild cost is y = 5.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 38 / 54

slide-128
SLIDE 128

Problem I: Partition of Queries Details

Details

In this problem, you have to decide when to rebuild a data structure so that the total time for processing the given queries is minimized. Example: queries are “++??+?”, rebuild cost is y = 5. Without interfering, we get the total cost 2 + 2 + 3 = 7.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 38 / 54

slide-129
SLIDE 129

Problem I: Partition of Queries Details

Details

In this problem, you have to decide when to rebuild a data structure so that the total time for processing the given queries is minimized. Example: queries are “++??+?”, rebuild cost is y = 5. Without interfering, we get the total cost 2 + 2 + 3 = 7. We put a rebuild after two adds: “++|??+?”, then the cost is 5 + 0 + 0 + 1 = 6.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 38 / 54

slide-130
SLIDE 130

Problem I: Partition of Queries Dynamic Programming 1

Dynamic Programming 1

Compute the prefix sums: p(i) is the number of “+” up to position i, r(i) is the number of “?” up to position i. Positions are numbered from 1 to n, prefix sums from 0 to n.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 39 / 54

slide-131
SLIDE 131

Problem I: Partition of Queries Dynamic Programming 1

Dynamic Programming 1

Compute the prefix sums: p(i) is the number of “+” up to position i, r(i) is the number of “?” up to position i. Positions are numbered from 1 to n, prefix sums from 0 to n. Let c(i) be the cost to process the first i queries without rebuilds: The c(i) = c(i − 1), plus p(i) if the i-th query is a “?”.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 39 / 54

slide-132
SLIDE 132

Problem I: Partition of Queries Dynamic Programming 1

Dynamic Programming 1

Compute the prefix sums: p(i) is the number of “+” up to position i, r(i) is the number of “?” up to position i. Positions are numbered from 1 to n, prefix sums from 0 to n. Let c(i) be the cost to process the first i queries without rebuilds: The c(i) = c(i − 1), plus p(i) if the i-th query is a “?”. Let s(j, i) be the cost to process all queries from the segment from j + 1 to i inclusive without rebuilds. Then s(j, i) = c(i) − c(j) − p(i) · (r(j) − r(i)). Indeed, we consider only the (r(j) − r(i)) “?” on the respective positions, and for each of them, we have to subtract p(i) “+” before that position.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 39 / 54

slide-133
SLIDE 133

Problem I: Partition of Queries Dynamic Programming 2

Dynamic Programming 2

Finally, let f (i) be the minimum possible cost to process the first i queries: we either process all of them, or insert a rebuild after position j < i, take f (j) into account, and process all queries from the segment from j + 1 to i inclusive without rebuilds.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 40 / 54

slide-134
SLIDE 134

Problem I: Partition of Queries Dynamic Programming 2

Dynamic Programming 2

Finally, let f (i) be the minimum possible cost to process the first i queries: we either process all of them, or insert a rebuild after position j < i, take f (j) into account, and process all queries from the segment from j + 1 to i inclusive without rebuilds. So, f (i) = min{c(i), c(j) + s(j, i) + y for all j < i}. The answer we want is f (n).

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 40 / 54

slide-135
SLIDE 135

Problem I: Partition of Queries Dynamic Programming 3

Dynamic Programming 3

Let us make some adjustments to the formula: f (i) = min{c(i), b(j, i) for all j < i}, where b(j, i) = c(j) + s(j, i) + y. Naturally, b(j, i) = c(j)+c(i)−c(j)−p(i)·(r(j)−r(i)) = c(i)+p(i)·r(i)−p(i)·r(j).

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 41 / 54

slide-136
SLIDE 136

Problem I: Partition of Queries Dynamic Programming 3

Dynamic Programming 3

Let us make some adjustments to the formula: f (i) = min{c(i), b(j, i) for all j < i}, where b(j, i) = c(j) + s(j, i) + y. Naturally, b(j, i) = c(j)+c(i)−c(j)−p(i)·(r(j)−r(i)) = c(i)+p(i)·r(i)−p(i)·r(j). Now consider everything depending only on i as a separate function: g(i) = c(i) + p(i) · r(i). Then g(i) − b(j, i) is just p(i) · r(j). Note that p(i) and r(j) are nondecreasing sequences. So it turns out we can use some “convex hull” optimization to compute the minimums efficiently: do a binary search for the respective j, or do two pointers, as when i increases, j can not decrease.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 41 / 54

slide-137
SLIDE 137

Problem J: Random Chess Game Statement

Statement Problem J: Random Chess Game

In this problem, you have to win 150 chess games against an opponent who picks random moves, and all possible moves are listed for you each time you have to make a move.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 42 / 54

slide-138
SLIDE 138

Problem J: Random Chess Game Details

Details

In this problem, you have to win 150 chess games against an opponent who picks random moves, and all possible moves are listed for you each time you have to make a move. Implementing all chess rules from scratch is very hard to do in a contest.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 43 / 54

slide-139
SLIDE 139

Problem J: Random Chess Game Details

Details

In this problem, you have to win 150 chess games against an opponent who picks random moves, and all possible moves are listed for you each time you have to make a move. Implementing all chess rules from scratch is very hard to do in a contest. Thus a more realistic approach is to use the provided move generator, consider only a part of game state, and use heuristics for the rest.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 43 / 54

slide-140
SLIDE 140

Problem J: Random Chess Game Details

Details

In this problem, you have to win 150 chess games against an opponent who picks random moves, and all possible moves are listed for you each time you have to make a move. Implementing all chess rules from scratch is very hard to do in a contest. Thus a more realistic approach is to use the provided move generator, consider only a part of game state, and use heuristics for the rest. There are two sources for heuristics:

We know chess rules. We know the opponent picks moves uniformly at random.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 43 / 54

slide-141
SLIDE 141

Problem J: Random Chess Game Details

Details

In this problem, you have to win 150 chess games against an opponent who picks random moves, and all possible moves are listed for you each time you have to make a move. Implementing all chess rules from scratch is very hard to do in a contest. Thus a more realistic approach is to use the provided move generator, consider only a part of game state, and use heuristics for the rest. There are two sources for heuristics:

We know chess rules. We know the opponent picks moves uniformly at random.

Be ready to iterate, and likely not have your solution accepted on the first try.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 43 / 54

slide-142
SLIDE 142

Problem J: Random Chess Game Heuristics

Heuristics

If there is a checkmate move, do it!

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 44 / 54

slide-143
SLIDE 143

Problem J: Random Chess Game Heuristics

Heuristics

If there is a checkmate move, do it! We strive to take Black’s pieces...

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 44 / 54

slide-144
SLIDE 144

Problem J: Random Chess Game Heuristics

Heuristics

If there is a checkmate move, do it! We strive to take Black’s pieces... but we don’t like to put the Black King in check: too little responses, too high the probability of a good response.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 44 / 54

slide-145
SLIDE 145

Problem J: Random Chess Game Heuristics

Heuristics

If there is a checkmate move, do it! We strive to take Black’s pieces... but we don’t like to put the Black King in check: too little responses, too high the probability of a good response. Prefer moving pawns to moving heavier pieces...

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 44 / 54

slide-146
SLIDE 146

Problem J: Random Chess Game Heuristics

Heuristics

If there is a checkmate move, do it! We strive to take Black’s pieces... but we don’t like to put the Black King in check: too little responses, too high the probability of a good response. Prefer moving pawns to moving heavier pieces... but avoid moving pawns adjacent to the White King, just to keep the King safe.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 44 / 54

slide-147
SLIDE 147

Problem J: Random Chess Game Heuristics

Heuristics

If there is a checkmate move, do it! We strive to take Black’s pieces... but we don’t like to put the Black King in check: too little responses, too high the probability of a good response. Prefer moving pawns to moving heavier pieces... but avoid moving pawns adjacent to the White King, just to keep the King safe. Strive for promoting your pawns.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 44 / 54

slide-148
SLIDE 148

Problem J: Random Chess Game Heuristics

Heuristics

If there is a checkmate move, do it! We strive to take Black’s pieces... but we don’t like to put the Black King in check: too little responses, too high the probability of a good response. Prefer moving pawns to moving heavier pieces... but avoid moving pawns adjacent to the White King, just to keep the King safe. Strive for promoting your pawns. Avoid placing heavy pieces adjacent to the Black King.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 44 / 54

slide-149
SLIDE 149

Problem J: Random Chess Game Heuristics

Heuristics

If there is a checkmate move, do it! We strive to take Black’s pieces... but we don’t like to put the Black King in check: too little responses, too high the probability of a good response. Prefer moving pawns to moving heavier pieces... but avoid moving pawns adjacent to the White King, just to keep the King safe. Strive for promoting your pawns. Avoid placing heavy pieces adjacent to the Black King. Avoid repeated positions, which can be indirectly tracked as their sets

  • f possible moves.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 44 / 54

slide-150
SLIDE 150

Problem J: Random Chess Game Heuristics

Heuristics

If there is a checkmate move, do it! We strive to take Black’s pieces... but we don’t like to put the Black King in check: too little responses, too high the probability of a good response. Prefer moving pawns to moving heavier pieces... but avoid moving pawns adjacent to the White King, just to keep the King safe. Strive for promoting your pawns. Avoid placing heavy pieces adjacent to the Black King. Avoid repeated positions, which can be indirectly tracked as their sets

  • f possible moves.

In the endgame, minimize distance between Kings to avoid draws by 50-move rule...

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 44 / 54

slide-151
SLIDE 151

Problem J: Random Chess Game Heuristics

Heuristics

If there is a checkmate move, do it! We strive to take Black’s pieces... but we don’t like to put the Black King in check: too little responses, too high the probability of a good response. Prefer moving pawns to moving heavier pieces... but avoid moving pawns adjacent to the White King, just to keep the King safe. Strive for promoting your pawns. Avoid placing heavy pieces adjacent to the Black King. Avoid repeated positions, which can be indirectly tracked as their sets

  • f possible moves.

In the endgame, minimize distance between Kings to avoid draws by 50-move rule... but be careful not to produce a stalemate.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 44 / 54

slide-152
SLIDE 152

Problem J: Random Chess Game Scholar’s Mate

Scholar’s Mate

Try Scholar’s Mate first!

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 45 / 54

slide-153
SLIDE 153

Problem J: Random Chess Game Scholar’s Mate

Scholar’s Mate

Try Scholar’s Mate first! For example: 1.e4, 2.Nf3, 3.Bc4, 4.Ne5, 5.Qf3.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 45 / 54

slide-154
SLIDE 154

Problem J: Random Chess Game Scholar’s Mate

Scholar’s Mate

Try Scholar’s Mate first! For example: 1.e4, 2.Nf3, 3.Bc4, 4.Ne5, 5.Qf3. If this does not work, consider moving the Queen back, then proceed normally with heuristics.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 45 / 54

slide-155
SLIDE 155

Problem K: What? Subtasks? Again? Statement

Statement Problem K: What? Subtasks? Again?

In this problem, you have to pick a subset of contest features so that the number of satisfied contestants is the maximum possible integer m.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 46 / 54

slide-156
SLIDE 156

Problem K: What? Subtasks? Again? Details

Details

In this problem, you have to pick a subset of contest features so that the number of satisfied contestants is the maximum possible integer m. There are exactly five features!

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 47 / 54

slide-157
SLIDE 157

Problem K: What? Subtasks? Again? Details

Details

In this problem, you have to pick a subset of contest features so that the number of satisfied contestants is the maximum possible integer m. There are exactly five features! For each contestant, compute the mask of features they don’t like.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 47 / 54

slide-158
SLIDE 158

Problem K: What? Subtasks? Again? Details

Details

In this problem, you have to pick a subset of contest features so that the number of satisfied contestants is the maximum possible integer m. There are exactly five features! For each contestant, compute the mask of features they don’t like. For each of the 25 = 32 possible sets of features, count the contestants satisfied by this set.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 47 / 54

slide-159
SLIDE 159

Problem K: What? Subtasks? Again? Details

Details

In this problem, you have to pick a subset of contest features so that the number of satisfied contestants is the maximum possible integer m. There are exactly five features! For each contestant, compute the mask of features they don’t like. For each of the 25 = 32 possible sets of features, count the contestants satisfied by this set. Pick the greatest number of contestants m.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 47 / 54

slide-160
SLIDE 160

Problem K: What? Subtasks? Again? Details

Details

In this problem, you have to pick a subset of contest features so that the number of satisfied contestants is the maximum possible integer m. There are exactly five features! For each contestant, compute the mask of features they don’t like. For each of the 25 = 32 possible sets of features, count the contestants satisfied by this set. Pick the greatest number of contestants m. If there is none, print the required line instead of the number.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 47 / 54

slide-161
SLIDE 161

Problem L: The Five Bishops Statement

Statement Problem L: The Five Bishops

In this problem, you have to checkmate or stalemate a lone black King with five white bishops on an infinite chessboard.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 48 / 54

slide-162
SLIDE 162

Problem L: The Five Bishops Details

Details

In this problem, you have to checkmate or stalemate a lone black King with five white bishops on an infinite chessboard. If we don’t have two bishops of each color (two on light squares and two on dark squares), we can’t do it.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 49 / 54

slide-163
SLIDE 163

Problem L: The Five Bishops Details

Details

In this problem, you have to checkmate or stalemate a lone black King with five white bishops on an infinite chessboard. If we don’t have two bishops of each color (two on light squares and two on dark squares), we can’t do it. Four bishops are sufficient.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 49 / 54

slide-164
SLIDE 164

Problem L: The Five Bishops Getting Far

Getting Far

Step 1: Get far from the King.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 50 / 54

slide-165
SLIDE 165

Problem L: The Five Bishops Getting Far

Getting Far

Step 1: Get far from the King. Be careful not to lose any important bishop.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 50 / 54

slide-166
SLIDE 166

Problem L: The Five Bishops Getting Far

Getting Far

Step 1: Get far from the King. Be careful not to lose any important bishop. The King can’t attack both colors simultaneously.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 50 / 54

slide-167
SLIDE 167

Problem L: The Five Bishops Getting Far

Getting Far

Step 1: Get far from the King. Be careful not to lose any important bishop. The King can’t attack both colors simultaneously. Defend one bishop of the attacked color with another.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 50 / 54

slide-168
SLIDE 168

Problem L: The Five Bishops Getting Far

Getting Far

Step 1: Get far from the King. Be careful not to lose any important bishop. The King can’t attack both colors simultaneously. Defend one bishop of the attacked color with another. We can lose the third bishop of some color, or just move it away.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 50 / 54

slide-169
SLIDE 169

Problem L: The Five Bishops Getting Far

Getting Far

Step 1: Get far from the King. Be careful not to lose any important bishop. The King can’t attack both colors simultaneously. Defend one bishop of the attacked color with another. We can lose the third bishop of some color, or just move it away. Bearing that in mind, move the bishops away (say, 106 squares) from the King.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 50 / 54

slide-170
SLIDE 170

Problem L: The Five Bishops Controlling the Diagonals

Controlling the Diagonals

Step 2: Bound the King to one diagonal line.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 51 / 54

slide-171
SLIDE 171

Problem L: The Five Bishops Controlling the Diagonals

Controlling the Diagonals

Step 2: Bound the King to one diagonal line. Consider one of the two types diagonals of the board.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 51 / 54

slide-172
SLIDE 172

Problem L: The Five Bishops Controlling the Diagonals

Controlling the Diagonals

Step 2: Bound the King to one diagonal line. Consider one of the two types diagonals of the board. Enumerate them by integers, for example, c = x − y.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 51 / 54

slide-173
SLIDE 173

Problem L: The Five Bishops Controlling the Diagonals

Controlling the Diagonals

Step 2: Bound the King to one diagonal line. Consider one of the two types diagonals of the board. Enumerate them by integers, for example, c = x − y. Let the King be on diagonal k.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 51 / 54

slide-174
SLIDE 174

Problem L: The Five Bishops Controlling the Diagonals

Controlling the Diagonals

Step 2: Bound the King to one diagonal line. Consider one of the two types diagonals of the board. Enumerate them by integers, for example, c = x − y. Let the King be on diagonal k. Then place the bishops on diagonals k − 10, k − 9, k + 9, and k + 10. As a result, the King can’t get to diagonals k + x where |x| 9.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 51 / 54

slide-175
SLIDE 175

Problem L: The Five Bishops Controlling the Diagonals

Controlling the Diagonals

Step 2: Bound the King to one diagonal line. Consider one of the two types diagonals of the board. Enumerate them by integers, for example, c = x − y. Let the King be on diagonal k. Then place the bishops on diagonals k − 10, k − 9, k + 9, and k + 10. As a result, the King can’t get to diagonals k + x where |x| 9. As long as there is more than one diagonal left for the King, pick the bishop on the diagonal farthest from the King, and move it one step closer.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 51 / 54

slide-176
SLIDE 176

Problem L: The Five Bishops Controlling the Diagonals

Controlling the Diagonals

Step 2: Bound the King to one diagonal line. Consider one of the two types diagonals of the board. Enumerate them by integers, for example, c = x − y. Let the King be on diagonal k. Then place the bishops on diagonals k − 10, k − 9, k + 9, and k + 10. As a result, the King can’t get to diagonals k + x where |x| 9. As long as there is more than one diagonal left for the King, pick the bishop on the diagonal farthest from the King, and move it one step closer. The King won’t be attacked by this move, but the number of diagonals he can visit will decrease by one.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 51 / 54

slide-177
SLIDE 177

Problem L: The Five Bishops Stalemate

Stalemate

Step 3: Produce a stalemate.

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 52 / 54

slide-178
SLIDE 178

Problem L: The Five Bishops Stalemate

Stalemate

Step 3: Produce a stalemate.

K K K

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 52 / 54

slide-179
SLIDE 179

Problem L: The Five Bishops Stalemate

Stalemate

Step 3: Produce a stalemate.

K K K K K K

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 52 / 54

slide-180
SLIDE 180

Credits Credits

Based on LV St. Petersburg State University Championship Contest Developers: Ivan Kazmenko Aleksandr Logunov Andrei Lopatin Anton Maydell Artur Riazanov

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 53 / 54

slide-181
SLIDE 181

Questions?

Ivan Kazmenko (SPb SU) Problem Analysis 28.01.2020 54 / 54