We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<iostream>#include<cstring>usingnamespacestd;#define long long longconstintmaxn=210;constintmod=1000000007;intn,m,s;charmap[maxn][maxn];longans[maxn][maxn];longsum[maxn][2*maxn];voidinit(){cin>>n>>m>>s;for(inti=0;i<n;++i)cin>>map[i];}longgetsum(intx,inty){if(x<0){y+=x;x=0;}if(x>=n){y=y-x+n-1;x=n-1;}if(y<0)return0;returnsum[x][y];}voidcalc_sum(){for(intj=0;j<2*n;++j)for(inti=0;i<n;++i){if(j>=n)sum[i][j]=0;elsesum[i][j]=ans[i][j];sum[i][j]=(sum[i][j]+getsum(i-1,j-1)+getsum(i+1,j-1)-getsum(i,j-2)+mod)%mod;}}voidsolve(){memset(ans,0,sizeof(ans));for(inti=0;i<n;++i)for(intj=0;j<n;++j)if(map[i][j]=='L')ans[i][j]=1;for(intk=1;k<=m;++k){calc_sum();for(inti=0;i<n;++i)for(intj=0;j<n;++j)if(map[i][j]=='P')ans[i][j]=0;else{ans[i][j]=(getsum(i,j+s)-getsum(i-s-1,j-1)-getsum(i+s+1,j-1)+getsum(i,j-s-2)+mod+mod)%mod;ans[i][j]=(ans[i][j]+getsum(i,j+s-1)-getsum(i-s,j-1)-getsum(i+s,j-1)+getsum(i,j-s-1)+mod+mod)%mod;}}longres=0;for(inti=0;i<n;++i)for(intj=0;j<n;++j)res=(res+ans[i][j])%mod;cout<<res<<endl;}intmain(){intt;cin>>t;while(t--){init();solve();}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Fairy Chess
You are viewing a single comment's thread. Return to all comments →