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

Mall Together-TENOKE

Simulation gaming enthusiasts have a fresh operational challenge to...

7 Reasons This Coffee...

📢 As an Amazon Associate, I earn from qualifying...

Why Kitchen Organization Tools...

📢 As an Amazon Associate, I earn from qualifying...

Is Dorm Room Hacks...

📢 As an Amazon Associate, I earn from qualifying...

Stop Buying Cheap Alternatives...

📢 As an Amazon Associate, I earn from qualifying...

Everything You Need to...

📢 As an Amazon Associate, I earn from qualifying...

Mall Together-TENOKE

Simulation gaming enthusiasts have a fresh operational challenge to tackle with the arrival of Mall Together-TENOKE. This brand-new release delivers an immersive shopping mall...

7 Reasons This Coffee Bar Accessories Is Worth Every Single Penny

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Why Kitchen Organization Tools Is Currently Breaking the Internet

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Is Dorm Room Hacks Worth Your Money Here Is Our Full Review

📢 As an Amazon Associate, I earn from qualifying purchases.If you had told me six months ago that a single purchase would change how...

Stop Buying Cheap Alternatives This Camping Essentials Is the Real Deal

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Everything You Need to Know About Outdoor Patio Tech Right Now

📢 As an Amazon Associate, I earn from qualifying purchases.I'll be honest — I was skeptical at first. My daily routine had a gap...

Why Bathroom Organization Hacks Is Currently Breaking the Internet

📢 As an Amazon Associate, I earn from qualifying purchases.I'll be honest — I was skeptical at first. My daily routine had a gap...

Why Electric Cleaning Tools Is Currently Breaking the Internet

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Electric Cleaning Tools?The Electric Cleaning Tools...

Everything You Need to Know About Portable Cooling Gear Right Now

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Portable Cooling Gear?The Portable Cooling Gear...