Sponsors

Codeforces Round #390 (Div. 2), problem: (E) Dasha and Cyclic Table Solution in C/C++

Codeforces Round #390 (Div. 2), problem: (E) Dasha and Cyclic Table Solution in C/C++

 

 

 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 401;

bitset<N> rc[N][N][26];
string s[N];
string q[N];
int n, m;
int r, c;

void init() {
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            char c = s[i][j];
            for (int s = 0; s < m; s++)
                rc[i][s][c - 'a'].set((j - s + m) % m);        
        }
}

bitset<N> solve(int st) {
    bitset<N> res;
    res.set();
    for (int i = 0; i < r; i++) {
        int row = (st + i) % n;
        for (int j = 0; j < c; j++)
            if (q[i][j] != '?') 
                res &= rc[row][j % m][q[i][j] - 'a'];   
    }  
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> s[i];
    cin >> r >> c;
    for (int i = 0; i < r; i++)
        cin >> q[i];
    init();
    for (int i = 0; i < n; i++) {
        auto b = solve(i);
        for (int j = 0; j < m; j++)
            if (b[j])
                cout << '1';
            else
                cout << '0';
        cout << "\n";    
    }
}

Ronda Rousey vs. Gina...

The Dream Match: Ronda Rousey vs. Gina Carano at...

Why Everyone is Obsessed with the Portable Handheld Misting Fan

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...

Why Everyone is Obsessed with the Mini Magnetic Bag Sealer

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...

Ronda Rousey vs. Gina Carano MVP MMA live blog

The Dream Match: Ronda Rousey vs. Gina Carano at MVP MMA The world of mixed martial arts is currently witnessing a moment many thought would...

Why Everyone is Obsessed with the Electric Spin Scrubber Pro

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...

Why Everyone is Obsessed with the Mini Magnetic Bag Sealer

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...

Why Everyone is Obsessed with the Electric Spin Scrubber Pro

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...

Why Everyone is Obsessed with the Sunset Projection Lamp LED

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...

Why Everyone is Obsessed with the Electric Spin Scrubber Cordless

Are you tired of dealing with everyday frustrations that slow down your routine? We've all been...

The Ultimate Guide to the Keyboard and Car Universal Cleaning Gel

I discovered the Keyboard and Car Universal Cleaning Gel and it is a total game-changer for my daily routine. Here is why you need...