# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
956168 | samvar_0907 | Snake Escaping (JOI18_snake_escaping) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int l, q;
cin >> l >> q;
string toxicities;
cin >> toxicities;
while (q--){
string s;
cin >> s;
int ans = 0;
for (int bm = 0; bm < (1 << l); bm++){
bool add = true;
for (int i = l - 1; i >= 0; i--){
if (s[i] == '0' || s[i] == '1'){
int s_digit = s[i] - '0';
int bm_bit = (bm >> (l - i - 1)) & 1;
if (s_digit != bm_bit) {
add = false;
break;
}
}
}
}
if (add){
ans += toxicities[bm]-'0';
}
cout << ans;
}
return 0;
}