Title link
D. Walk on Matrix
Topic: Give you a k, and ask you to construct a weight matrix of n * m. Bob asks according to this dp:
And the true route maximum of this matrix minus dp [n] [m] obtained by Bob is equal to k.
Idea: Obviously let Bob's dp [n] [m] be 0 and it is better to construct, I just need to construct k to do it. After spending a page of draft paper, I finally found out how to understand:
Let len be the length in k binary, which is exactly one bit larger than k.
m=1<<len
k+m m m k
k m+k k k
Bob's route: (1,1) (1,2) (2,2) (2,3) (2,4) The corresponding weight is: k + m-> m-> m-> 0-> 0
The correct route (1,1) (2,1) (2,2) (2,3) (2,4) corresponds to a weight of k + m-> k-> k-> k-> k
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N=5e2+10;
int dp[N][N],a[N][N],n,m,k;
int main()
{
n=2,m=4;
cin>>k;
int x=k,len=0;
while(x)++len,x=x/2;
a[1][4]=a[2][1]=a[2][3]=a[2][4]=k;
//len++;
a[1][2]=a[1][3]=1<<len;
int t=0;
a[1][1]=a[2][2]=a[1][2]+k;
printf("%d %d\n",n,m);
rep(i,1,n)
{
rep(j,1,m) printf("%d ",a[i][j]);
puts("");
}
}
/*
84306
*/
E. Height All the Same
Topic: Give you n, m, l, r to ask how many original matrices you have, l <= a [i] [j] <= r Make the height as high as the following two operations:
1: Choose an increase of 2 heights,
2: Choose two to raise one height at the same time
Idea: No, search solution: From: This
In fact, when n * m is even, and the odd number in the matrix is odd, and the even number is odd, it is an illegal matrix.
Then use (r-l + 1) ^ (n * m)-illegal
Illegal =
(r-l+1)^(n*m) - =
#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;
ll n,m,l,r,ans;
ll ppow(ll a,ll x)
{
ll tans=1;
while(x)
{
if(x&1)tans=tans*a%mod;
a=a*a%mod;x>>=1;
}
return tans;
}
int main()
{
scanf("%lld%lld%lld%lld",&n,&m,&l,&r);
if((n*m)&1)ans=ppow(r-l+1,n*m);
else ans=(ppow(r-l+1,n*m)+ppow((r-l+2)/2-(r-l+1)/2,n*m))*ppow(2,mod-2)%mod;
printf("%lld\n",ans);
return 0;
}