Submission #1137756

#TimeUsernameProblemLanguageResultExecution timeMemory
1137756varun312Snake Escaping (JOI18_snake_escaping)C++20
12 / 100
2096 ms7932 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define endl "\n"

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(0);

    int l,q;
    cin >> l >> q;
    int n = (1 << l);
    string s;
    cin >> s;
    unordered_map<string, int> cache;
    while (q--) {
        string a;
        cin >> a;
        if (cache.find(a) != cache.end()) {
            cout << cache[a] << endl;
            continue;
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int bit = 0; bit < l; bit++) {
                if ((a[l-bit-1] != '?') && ((a[l-bit-1] == '1') != (bool)(i & (1 << bit)))) {
                    goto nah;
                }
            }
            // cout << i << " ";
            ans += s[i]-'0';
            nah:
            continue;
        }
        cache[a] = ans;
        cout << ans << endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...