CF1332D.Walk on Matrix
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Bob is playing a game named "Walk on Matrix".
In this game, player is given an n×m matrix A=(ai,j), i.e. the element in the i-th row in the j-th column is ai,j. Initially, player is located at position (1,1) with score a1,1.
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.
However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.
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.

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×m matrix A=(ai,j) such that
- 1≤n,m≤500 (as Bob hates large matrix);
- 0≤ai,j≤3⋅105 for all 1≤i≤n,1≤j≤m (as Bob hates large numbers);
- the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0≤k≤105, there exists a matrix satisfying the above constraints.
Please help him with it!
鲍勃正在玩一个名为“矩阵行走”的游戏。
在这个游戏中,玩家会得到一个 n×m 的矩阵 A=(ai,j),即第 i 行第 j 列的元素为 ai,j。初始时,玩家位于位置 (1,1),得分为 a1,1。
为了到达目标位置 (n,m),玩家每次只能向右或向下移动,即从 (x,y) 移动到 (x,y+1) 或 (x+1,y),前提是移动后仍在矩阵范围内。
然而,每次移动都会将玩家当前得分更新为:当前得分与所移入位置处的矩阵元素值的按位与(bitwise AND)。
鲍勃迫不及待地想用自己最近学过的工具——动态规划——来求出他所能获得的最大得分。以下是他的算法:

然而,他突然意识到上述算法对某些矩阵 A 并不能输出正确的最大得分。因此,对于任意给定的非负整数 k,他希望构造一个满足以下条件的 n×m 矩阵 A=(ai,j):
- 1≤n,m≤500(因为鲍勃讨厌过大的矩阵);
- 对所有 1≤i≤n,1≤j≤m,均有 0≤ai,j≤3⋅105(因为鲍勃讨厌过大的数);
- 玩家实际能获得的最大得分与他上述算法输出结果之间的差值恰好为 k。
可以证明:对任意满足 0≤k≤105 的整数 k,均存在满足上述约束的矩阵。
请帮助他完成这一任务!
输入格式
The only line of the input contains one single integer k (0≤k≤105).
输入仅包含一行,其中有一个整数 k(0≤k≤105)。
输出格式
Output two integers n, m (1≤n,m≤500) in the first line, representing the size of the matrix.
Then output n lines with m integers in each line, ai,j in the (i+1)-th row, j-th column.
第一行输出两个整数 n、m(1≤n,m≤500),表示矩阵的大小。
随后输出 n 行,每行包含 m 个整数,其中第 (i+1) 行第 j 列的元素为 ai,j。
输入输出样例
输入#1
0
输出#1
1 1 300000
输入#2
1
输出#2
3 4 7 3 3 1 4 8 3 6 7 7 7 3
说明/提示
In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000.
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.
在第一个例子中,Bob 能够获得的最高分数为 300000,而他所用算法的输出结果也为 300000。
在第二个例子中,Bob 能够获得的最高分数为 7&3&3&3&7&3=3,而他所用算法的输出结果为 2。
输入解题思路,AI测评打分。不知道怎么写?