이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int DP1[1048576];
int DP2[1048576];
int arr[1048576];
int applymaskques(const string &s,int mask){
int ans = 0;
for(int bit=0;bit<s.size();bit++){
if(s[bit]=='?'){
if(mask&1)ans|=(1<<bit);
mask>>=1;
} else {
if(s[bit]=='1')ans|=(1<<bit);
}
}
return ans;
}
int applymask(const string &s,int mask,char to){
int ans = 0;
for(int bit=0;bit<s.size();bit++){
if(s[bit]=='?'){
if(to=='1')ans|=(1<<bit);
} else if(s[bit]==to){
if(mask&1)ans|=(1<<bit);
mask>>=1;
} else {
if(to=='0')ans|=(1<<bit);
}
}
return ans;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int l,q;
cin >> l >> q;
for(int mask=0;mask<(1<<l);mask++){
char a;cin>>a;a-='0';
DP1[mask]=DP2[mask]=arr[mask]=a;
}
for(int bit=0;bit<20;bit++){
for(int mask=0;mask<(1<<20);mask++){
if(mask&(1<<bit)){
DP2[mask^(1<<bit)]+=DP2[mask];
} else {
DP1[mask|(1<<bit)]+=DP1[mask];
}
}
}
for(int i=1;i<=q;i++){
string s;cin>>s;
reverse(s.begin(),s.end());
int c1=0,c0=0,cq=0;
for(char&j:s)if(j=='1')c1++;
for(char&j:s)if(j=='0')c0++;
for(char&j:s)if(j=='?')cq++;
if(c0<=6){
int ans = 0;
for(int mask=0;mask<(1<<c0);mask++){
if(__builtin_parity(mask)){
ans-=DP2[applymask(s,mask,'0')];
} else {
ans+=DP2[applymask(s,mask,'0')];
}
}
cout<<ans<<'\n';
continue;
}
if(c1<=6){
int ans = 0;
for(int mask=0;mask<(1<<c1);mask++){
if(__builtin_parity(mask)==(c1&1)){
ans+=DP1[applymask(s,mask,'1')];
} else {
ans-=DP1[applymask(s,mask,'1')];
}
}
cout<<ans<<'\n';
continue;
}
if(cq<=6){
int ans = 0;
for(int mask=0;mask<(1<<cq);mask++){
ans+=arr[applymaskques(s,mask)];
}
cout<<ans<<'\n';
continue;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
snake_escaping.cpp: In function 'long long int applymaskques(const string&, long long int)':
snake_escaping.cpp:12:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for(int bit=0;bit<s.size();bit++){
| ~~~^~~~~~~~~
snake_escaping.cpp: In function 'long long int applymask(const string&, long long int, char)':
snake_escaping.cpp:25:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int bit=0;bit<s.size();bit++){
| ~~~^~~~~~~~~
# | 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... |