이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// FUCKED UP FUCKED UP FUCKED UP FUCKED UP FUCKED UP
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn=2e3+10, maxm=1e6+10, lg=21, mod=1e9+7, inf=1e18;
#define bone(x) (__builtin_popcount(x))
ll L,Q;
string s;
ll s0[1<<lg],s1[1<<lg];
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>L>>Q>>s;
for(int m=0;m<SZ(s);m++){
ll xx=((1<<L)-1)^m;
for(int b=xx;;b=(b-1)&xx){
s1[m]+=s[m^b]-'0', s0[m]+=s[((1<<L)-1)^(m^b)]-'0';
if(!b) break;
}
}
while(Q--){
string t; cin>>t; reverse(all(t));
ll t0=0,t1=0,tq=0;
for(int i=0;i<L;i++){
if(t[i]=='0') t0^=(1<<i);
if(t[i]=='1') t1^=(1<<i);
if(t[i]=='?') tq+=(1<<i);
}
ll mn=min({bone(t0),bone(t1),bone(tq)}),ans=0;
if(mn==bone(tq)){
for(ll sub=tq;;sub=(sub-1)&tq){
ans+=s[sub^t1]-'0';
if(!sub) break;
};
}
else if(mn==bone(t1)){
for(ll sub=t1;;sub=(sub-1)&t1){
ans+=(bone(sub)%2==bone(t1)%2 ? +1:-1)*s0[sub^t0];
if(!sub) break;
}
}
else if(mn==bone(t0)){
for(ll sub=t0;;sub=(sub-1)&t0){
ans+=(bone(sub)%2==bone(t0)%2 ? +1:-1)*s1[sub^t1];
if(!sub) break;
}
}
cout<<ans<<'\n';
}
return 0;
}
# | 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... |