1332D.md (2350B)
1 Source: https://codeforces.com/problemset/problem/1332/D 2 3 D. Walk on Matrix 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 512 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Bob is playing a game named "Walk on Matrix". 22 23 In this game, player is given an $n \times m$ matrix $A=(a_{i,j})$, i.e. the element in the $i$-th row in the $j$-th column is $a_{i,j}$. Initially, player is located at position $(1,1)$ with score $a_{1,1}$. 24 25 To reach the goal, position $(n,m)$, player can move right or down, i.e. move from $(x,y)$ to $(x,y+1)$ or $(x+1,y)$, as long as player is still on the matrix. 26 27 However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to. 28 29 Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. 30 31  32 33 However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $A$. Thus, for any given non-negative integer $k$, he wants to find out an $n \times m$ matrix $A=(a_{i,j})$ such that 34 35 * $1 \le n,m \le 500$ (as Bob hates large matrix); 36 * $0 \le a_{i,j} \le 3 \cdot 10^5$ for all $1 \le i\le n,1 \le j\le m$ (as Bob hates large numbers); 37 * the difference between the maximum score he can get and the output of his algorithm is exactly $k$. 38 39 It can be shown that for any given integer $k$ such that $0 \le k \le 10^5$, there exists a matrix satisfying the above constraints. 40 41 Please help him with it! 42 43 Input 44 45 The only line of the input contains one single integer $k$ ($0 \le k \le 10^5$). 46 47 Output 48 49 Output two integers $n$, $m$ ($1 \le n,m \le 500$) in the first line, representing the size of the matrix. 50 51 Then output $n$ lines with $m$ integers in each line, $a_{i,j}$ in the $(i+1)$-th row, $j$-th column. 52 53 Examples 54 55 Input 56 57 ``` 58 0 59 ``` 60 61 Output 62 63 ``` 64 1 1 65 300000 66 ``` 67 68 Input 69 70 ``` 71 1 72 ``` 73 74 Output 75 76 ``` 77 3 4 78 7 3 3 1 79 4 8 3 6 80 7 7 7 3 81 ``` 82 83 Note 84 85 In the first example, the maximum score Bob can achieve is $300000$, while the output of his algorithm is $300000$. 86 87 In the second example, the maximum score Bob can achieve is $7\&3\&3\&3\&7\&3=3$, while the output of his algorithm is $2$.