QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#738253 | #7056. Chessboard | icpc_zhzx034# | WA | 0ms | 24296kb | C++14 | 3.2kb | 2024-11-12 18:25:14 | 2024-11-12 18:25:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
#define popcnt __builtin_popcountll
const ll mod = 998244353;
inline ll read(){
ll x=0, f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0' && ch<='9') x=x*10+ch-'0', ch=getchar();
return x*f;
}
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
inline ll qpow(ll a,ll b){
ll ans=1, base=a;
while(b){
if(b&1) ans=ans*base%mod;
base=base*base%mod; b>>=1;
}
return ans;
}
namespace math{
const ll N = 300000;
ll fac[N+5],inv[N+5];
ll qpow(ll a,ll b){
ll ans=1,base=a;
while(b){
if(b&1) ans=ans*base%mod;
base=base*base%mod; b>>=1;
}
return ans;
}
void init(){
fac[0]=inv[0]=1;
for(ll i=1;i<=N;i++) fac[i]=fac[i-1]*i%mod;
inv[N]=qpow(fac[N],mod-2);
for(ll i=N-1;i>=1;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
inline ll binom(ll x,ll y){
if(x<0 || y<0 || x<y) return 0;
return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
inline ll perm(ll x,ll y){
if(x<0 || y<0 || x<y) return 0;
return fac[x]*inv[x-y]%mod;
}
}
void init(){ }
ll n,m,dp[1005][1005],g[1005][1005];
ll calc(ll x,ll y){
if(x<0 || y<0) return 0;
if(x&1) return 0; if(y&1) return 0;
return math::binom((x+y)>>1, x>>1);
}
bool line(ll i){ return i==1||i==n; }
bool col(ll i){ return i==1||i==m; }
void addmod(ll &x){ if(x >= mod) x -= mod; }
void procedure(){
n=read(), m=read();
if(n==1 || m==1){
puts(n==m?"1":"2");
return;
}
ll ans=4*(dp[n][m]+g[n][m]+g[m][n])%mod;
// cout<<"one corner "<<ans/4<<endl;
// cout<<"ans = "<<ans<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(line(i) && col(j)) continue;
if(line(i)){
// addmod(ans += g[n][m-j+1]);
// addmod(ans += g[n][j]);
// if((m-j+1)&1){
for(int k=1;k<n;k++) (ans += dp[k][j] * dp[n-k-1][m-j]) %= mod;
// }
// if(j&1){
for(int k=1;k<n;k++) (ans += dp[k][m-j+1] * dp[n-k-1][j-1]) %= mod;
// }
}else if(col(j)){
// addmod(ans += g[m][n-i+1]);
// addmod(ans += g[m][i]);
// if((n-i+1)&1){
for(int k=1;k<m;k++) (ans += dp[k][i] * dp[m-k-1][n-i]) %= mod;
// }
// if(i&1){
for(int k=1;k<m;k++) (ans += dp[k][n-i+1] * dp[m-k-1][i-1]) %= mod;
// }
}
}
}
// cout<<"g[3][3] = "<<g[3][3]<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(line(i) || col(j)) continue;
// if((j-1)&1){
(ans += 4 * g[n-i+1][m-j+1] * dp[i-1][j-2]) %= mod;
// cout<<i<<" "<<j<<" contri "<<g[n-i+1][m-j+1]<<endl;
// }
// if((i-1)&1){
(ans += 4 * g[m-j+1][n-i+1] * dp[j-1][i-2]) %= mod;
// cout<<i<<" "<<j<<" contri "<<g[m-j+1][n-i+1]<<endl;
// }
}
}
printf("%lld\n", ans);
}
int main(){
#ifdef LOCAL
assert(freopen("input.txt","r",stdin));
assert(freopen("output.txt","w",stdout));
#endif
math::init();
for(int i=0;i<=1000;i++){
for(int j=0;j<=1000;j++){
if(i==0 || j==0) dp[i][j] = 1;
else dp[i][j] = calc(i-1, j-1) + calc(i-2, j-1) + calc(i-1, j-2);
g[i+1][j] = dp[i][j];
}
}
ll T=read();
init();
while(T--) procedure();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 24296kb
input:
4 1 3 3 2 3 3 4 4
output:
2 12 32 80
result:
wrong answer 3rd lines differ - expected: '24', found: '32'