Walk on Matrix

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!

Input
The only line of the input contains one single integer k (0≤k≤105).

Output
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.

Examples

input
0
output
1 1
300000
input
1
output
3 4
7 3 3 1
4 8 3 6
7 7 7 3

Note
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.
构造矩阵是个难点

#include<bits/stdc++.h>

#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define sc(a) scahf("%c",&a);
#define ss(a) scanf("%s",a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%lld\n",a)
#define pf(a) printf("%lf\n",a)
#define pc(a) putchar(a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i, a, b) for(register int i=a;i<=b;++i)
#define repd(i, a, b) for(register int i=a;i>=b;--i)
#define reps(s) for(register int i=head[s];i;i=Next[i])
#define ll long long
#define vi vector<int>
#define vc vector<char>
#define pii pair<int,int>
#define pll pair<long,long>
#define pil pair<int,long>
#define pli pair<long,int>
#define lowbit(x) ((x)&(-(x)))
#define ce(i, r) i==r?'\n':' '
#define pb push_back
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl

using namespace std;

inline int qr() {
    int f = 0, fu = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')fu = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        f = (f << 3) + (f << 1) + c - 48;
        c = getchar();
    }
    return f * fu;
}

int k;

int main() {
    k = qr();
    puts("2 3");
    printf("%d %d %d\n%d %d %d\n", (1 << 17) + k, 1 << 17, 0, k, (1 << 17) + k, k);
    return 0;
}
发布了360 篇原创文章 · 获赞 28 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_45323960/article/details/105337192
今日推荐