제출 #1304356

#제출 시각아이디문제언어결과실행 시간메모리
1304356KietJSnake Escaping (JOI18_snake_escaping)C++17
5 / 100
2096 ms2520 KiB
#include<bits/stdc++.h>
using namespace std;

#define ll long long 
#define pii pair<int, int>
#define fi first
#define se second

const int N = 1e6 + 5;

int L, Q;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  cin >> L >> Q;
  string s, t;
  cin >> s;
  int n = 1 << L;
  
  while (Q--) {
    cin >> t;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      bool ok = 1;
      for (int j = 0; j < L; j++) {
        char c = t[j];
        if (c == '?') continue;
        int bit = (i >> (L - 1 - j)) & 1;
        if (c == '0' && bit != 0) {ok = 0; break;}
        if (c == '1' && bit != 1) {ok = 0; break;}
      }
      if (ok) ans += (s[i] - '0');
    }
    cout << ans << '\n';
  }
}
#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...