이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = (1 << 20) + 9;
const ll inf = 1e9 + 7;
char c;
string s;
ll a[N];
ll L,Q,dp[N],dpR[N];
bool bit(ll x,ll i){
    return (x >> i) & 1;
}
ll take,now,ans;
void fQ(ll pos){
    if (pos >= L){
        //cout<<now<<"x\n";
        ans += a[now]; return;
    }
    if (s[pos] == '1'){
        now = now*2 + 1; fQ(pos + 1); now = (now - 1)/2;
    }
    else if (s[pos] == '0'){
        now = now*2; fQ(pos + 1); now /= 2;
    }
    else{
        now = now*2; fQ(pos + 1); now /= 2;
        now = now*2 + 1; fQ(pos + 1); now = (now - 1)/2;
    }
}
void f1(ll pos){
    if (pos >= L){
        //cout<<now<<"x\n";
        if (take%2 == 0) ans += dp[now];
        else ans -= dp[now];
        return;
    }
    if (s[pos] == '1'){
        now = now*2; take++; f1(pos + 1); now /= 2; take--;
        now = now*2 + 1; f1(pos + 1); now = (now - 1)/2;
    }
    else if (s[pos] == '0'){
        now = now*2; f1(pos + 1); now /= 2;
    }
    else{
        now = now*2 + 1; f1(pos + 1); now = (now - 1)/2;
    }
}
void f0(ll pos){
    if (pos >= L){
        if (take%2 == 0) ans += dpR[now];
        else ans -= dpR[now];
        return;
    }
    if (s[pos] == '1'){
        now = now*2 + 1; f0(pos + 1); now = (now - 1)/2;
    }
    else if (s[pos] == '0'){
        now = now*2 + 1; take++; f0(pos + 1); now = (now - 1)/2; take--;
        now = now*2; f0(pos + 1); now /= 2;
    }
    else{
        now = now*2; f0(pos + 1); now /= 2;
    }
}
int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".INP","r")){
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    cin>>L>>Q;
    for (ll i = 0;i < (1 << L);i++){
        cin>>c; a[i] = c - '0';
        dp[i] += a[i]; dpR[i] += a[i];
    }
    for (ll i = 0;i < L;i++){
        for (ll mask = 0;mask < (1 << L);mask++)
            if (bit(mask,i)) dp[mask] += dp[mask ^ (1 << i)];
        for (ll mask = (1 << L) - 1;mask >= 0;mask--)
            if (!bit(mask,i)) dpR[mask] += dpR[mask ^ (1 << i)];
    }
    while(Q--){
        cin>>s; ll cnt1 = 0,cnt0 = 0,cntQ = 0; take = now = ans = 0;
        for (ll i = 0;i < L;i++){
            if (s[i] == '1') cnt1++;
            else if (s[i] == '0') cnt0++;
            else cntQ++;
        }
        ll mn = min(cntQ,min(cnt1,cnt0));
        if (cntQ == mn) fQ(0);
        else if (cnt1 == mn) f1(0);
        else f0(0);
        cout<<ans<<"\n";
    }
}
컴파일 시 표준 에러 (stderr) 메시지
snake_escaping.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization O2
      | 
snake_escaping.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
snake_escaping.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    3 | #pragma target ("avx2")
      | 
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~| # | 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... |