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

Advertisement

spot_img

Is the Keurig K-Mini...

Keurig K-Mini Long-Term Review: 12 Months of Daily Brewing First-impression...

Can You Make Iced...

How to Brew Refreshing Iced Coffee with the Keurig...

Keurig K-Mini vs Keurig...

Keurig K-Mini vs Keurig K-Slim: Comparing Keurig’s Slimmest Brewers Keurig’s...

Best K-Cup Coffee Pods...

Top Rated K-Cup Coffee Pods for the Keurig K-Mini The...

How to Fix a...

How to Clear Needle Clogs and Fix Slow Flow...

Keurig K-Mini Auto-Off Feature...

Keurig K-Mini Energy Efficiency & Power Consumption Analysis As electricity...

Is the Keurig K-Mini Worth It Long Term? 1-Year Reliability, Durability & Value

Keurig K-Mini Long-Term Review: 12 Months of Daily Brewing First-impression reviews written after three days of testing can tell you how an appliance looks on...

Can You Make Iced Coffee with the Keurig K-Mini? Brew Temperature & Iced Recipes

How to Brew Refreshing Iced Coffee with the Keurig K-Mini During warm summer months, nothing satisfies quite like a tall glass of refreshing iced coffee....

Keurig K-Mini vs Keurig K-Slim: Multi-Cup Reservoir vs Ultra-Compact Brewer

Keurig K-Mini vs Keurig K-Slim: Comparing Keurig’s Slimmest Brewers Keurig’s product catalog features two popular models specifically marketed to space-conscious consumers: the ultra-compact Keurig K-Mini...

Best K-Cup Coffee Pods for Keurig K-Mini: Dark, Medium, Flavored & Decaf Roasts

Top Rated K-Cup Coffee Pods for the Keurig K-Mini The beauty of owning a Keurig K-Mini Single Serve Coffee Maker is universal pod compatibility. Unlike...

How to Fix a Clogged Keurig K-Mini: Exit Needle Cleaning & Troubleshooting Guide

How to Clear Needle Clogs and Fix Slow Flow on the Keurig K-Mini If your Keurig K-Mini suddenly dispenses half a cup of coffee, drips...

Keurig K-Mini Auto-Off Feature and Power Consumption: Energy Efficiency Tested

Keurig K-Mini Energy Efficiency & Power Consumption Analysis As electricity costs rise and consumers increasingly prioritize eco-conscious household appliances, power consumption has become an important...

Keurig K-Mini Dimensions and Cord Storage: Best Compact Coffee Maker for Dorms & RVs

Keurig K-Mini Dimensions & Space-Saving Ergonomics Countertop real estate in modern living spaces has never been tighter. In college dormitories, studio micro-apartments, home office workstations,...

How to Use Reusable K-Cup Coffee Filters with the Keurig K-Mini: Universal Pod Guide

How to Brew Fresh Ground Coffee in Your Keurig K-Mini While pre-packaged K-Cup pods deliver unbeatable morning convenience, they come with two distinct trade-offs: ongoing...

Keurig K-Mini vs Nespresso Vertuo Pop: Compact Coffee Maker Comparison

Keurig K-Mini vs Nespresso Vertuo Pop: The Battle of Compact Brewers Single-serve coffee has evolved into two dominant, competing ecosystems: the versatile, drip-style Keurig K-Cup...