이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
// #define int ll
using namespace std;
typedef long long ll;
const int maxn = 1594323 + 100;
int dp[maxn];
signed main() {
#ifdef PC
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int L, q;
cin >> L >> q;
string s;
cin >> s;
int n = (1 << L);
vector<int> step(L + 1, 1);
for (int i = 1; i <= L; i++)
step[i] = step[i - 1] * 3;
for (int i = 0; i < maxn; i++)
dp[i] = 0;
for (int i = 0; i < n; i++) {
int ic = i, now = 0;;
vector<int> have;
for (int j = 0; j < L; j++) {
have.pb(ic % 2);
ic /= 2;
}
reverse(have.begin(), have.end());
for (int j = 0; j < L; j++) {
now = now * 3 + have[j];
}
dp[now] = s[i] - '0';
}
for (int i = 0; i < maxn; i++) {
int pos = -1, ic = i;
for (int j = 0; j < L; j++) {
if(ic % 3 == 2) {
pos = j;
break;
}
ic /= 3;
}
if(pos == -1)
continue;
dp[i] += dp[i - step[pos] * 1] + dp[i - step[pos] * 2];
}
for (int i = 0; i < q; i++) {
string ask;
cin >> ask;
int now = 0;
for (int j = 0; j < L; j++) {
if(ask[j] == '0')
now = now * 3 + 0;
if(ask[j] == '1')
now = now * 3 + 1;
if(ask[j] == '?')
now = now * 3 + 2;
}
cout << dp[now] << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |