1004B.md (2673B)
1 Source: https://codeforces.com/problemset/problem/1004/B 2 3 B. Sonya and Exhibition 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. 22 23 There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions should contain exactly one flower: a rose or a lily. 24 25 She knows that exactly $m$ people will visit this exhibition. The $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies. 26 27 Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible. 28 29 Input 30 31 The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively. 32 33 Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. 34 35 Output 36 37 Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily. 38 39 If there are multiple answers, print any. 40 41 Examples 42 43 Input 44 45 ``` 46 5 3 47 1 3 48 2 4 49 2 5 50 ``` 51 52 Output 53 54 ``` 55 01100 56 ``` 57 58 Input 59 60 ``` 61 6 3 62 5 6 63 1 4 64 4 6 65 ``` 66 67 Output 68 69 ``` 70 110010 71 ``` 72 73 Note 74 75 In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions; 76 77 * in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; 78 * in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; 79 * in the segment $[2\ldots5]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$. 80 81 The total beauty is equal to $2+2+4=8$. 82 83 In the second example, Sonya can put roses in the third, fourth, and sixth positions, and lilies in the first, second, and fifth positions; 84 85 * in the segment $[5\ldots6]$, there are one rose and one lily, so the beauty is equal to $1\cdot 1=1$; 86 * in the segment $[1\ldots4]$, there are two roses and two lilies, so the beauty is equal to $2\cdot 2=4$; 87 * in the segment $[4\ldots6]$, there are two roses and one lily, so the beauty is equal to $2\cdot 1=2$. 88 89 The total beauty is equal to $1+4+2=7$.