Sort by

recency

|

16 Discussions

|

  • + 0 comments

    Lmao the editorial is wrong, it's not a rectangle but a diamond which is much trickier.

  • + 0 comments

    Grab trendy sneakers for girls online in Pakistan. Walkeaze provides you with the highest quality sneakers shoes for girls online at reasonable prices. So, buy the best sneaker from Walkeaze and look more fashionable.

  • + 0 comments

    Here is my solution in java, javascript, python , C, C++, Csharp HackerRank Fairy Chess Problem Solution

  • + 0 comments

    Here is Fairy Chess problem solution - https://programs.programmingoneonone.com/2021/07/hackerrank-fairy-chess-problem-solution.html

  • + 0 comments
    #include <iostream>
    #include <cstring>
    
    using namespace std;
    
    #define long long long
    
    const int maxn = 210;
    const int mod = 1000000007;
    
    int n, m, s;
    char map[maxn][maxn];
    long ans[maxn][maxn];
    long sum[maxn][2*maxn];
    
    void init(){
        cin >> n >> m >> s;
        for(int i = 0; i < n; ++i)
            cin >> map[i];
    }
    
    long getsum(int x, int y){
        if(x < 0) {
            y += x;
            x = 0;
        }
        if(x >= n) {
            y = y - x + n - 1;
            x = n - 1;
        }
        if(y < 0)
            return 0;
        return sum[x][y];
    }
    
    void calc_sum(){
        for(int j = 0; j < 2 * n; ++j)
            for(int i = 0; i < n; ++i){
                if(j >= n)
                    sum[i][j] = 0;
                else
                    sum[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;
            }
    }
    
    void solve() {
        memset(ans, 0, sizeof(ans));
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                if(map[i][j] == 'L')
                    ans[i][j] = 1;
        for(int k = 1; k <= m; ++k) {
            calc_sum();
            for(int i = 0; i < n; ++i)
                for(int j = 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;
                    }
        }
        long res = 0;
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                res = (res + ans[i][j]) % mod;
        cout << res << endl;
    }
    
    int main() {
        int t; cin >> t;
        while(t--){
            init();
            solve();
        }
    }