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";    
    }
}

Zydus Semaglutide approval: Delhi...

The Delhi High Court has stepped into a significant...

A Sea Cucumber’s Amputated...

The Mystery of the Undying Sea Cucumber TissueNature never...

Why Everyone is Obsessed with the Cable Management Box

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

Zydus Semaglutide approval: Delhi HC directs CDSCO to decide on patient safety concerns

The Delhi High Court has stepped into a significant pharmaceutical regulatory matter by directing the Central Drugs Standard Control Organisation (CDSCO) to address patient...

Why Everyone is Obsessed with the Shower Phone Holder Case

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

Why Everyone is Obsessed with the Universal Travel Adapter

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

Why Everyone is Obsessed with the Bamboo Cutting Board Set

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

A Sea Cucumber’s Amputated Tissue Refuses To Die. Could It Live Forever?

The Mystery of the Undying Sea Cucumber TissueNature never ceases to amaze, and the latest discovery in marine biology has left scientists questioning the...

Why Everyone is Obsessed with the Car Seat Gap Organizer

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

Why Everyone is Obsessed with the Reusable Lint Roller

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

DraftKings: Prediction Markets Are Eating This Company’s Lunch (Rating Downgrade)

The online sports betting landscape is shifting rapidly, and industry giant DraftKings (DKNG) is finding itself in increasingly turbulent waters. Once the undisputed darling...