This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
char S[(1 << 20)+1],T[21];
int sum0[1 << 20],sum1[1 << 20],bits[1 << 20];
int main() {
int i,j;
int L,Q;
scanf("%d %d %s",&L,&Q,S);
for (i = 0; i < (1 << L); i++) sum0[i] = sum1[i] = S[i]-'0';
for (i = 0; i < L; i++) {
for (j = 0; j < (1 << L); j++) {
if (j & (1 << i)) sum0[j] += sum0[j^(1 << i)];
else sum1[j] += sum1[j^(1 << i)];
}
}
for (i = 0; i < (1 << L); i++) {
for (j = 0; j < L; j++) {
if (i & (1 << j)) bits[i]++;
}
}
for (i = 0; i < Q; i++) {
scanf("%s",T);
reverse(T,T+L);
int a = 0,b = 0,c = 0,ca = 0,cb = 0,cc = 0;
for (j = 0; j < L; j++) {
if (T[j] == '0') a |= (1 << j),ca++;
else if (T[j] == '1') b |= (1 << j),cb++;
else c |= (1 << j),cc++;
}
int ans = 0;
if ((ca <= cb) && (ca <= cc)) {
for (j = a; j > 0; j = (j-1) & a) {
if (bits[j] & 1) ans -= sum1[j | b];
else ans += sum1[j | b];
}
ans += sum1[b];
}
else if ((cb <= ca) && (cb <= cc)) {
for (j = b; j > 0; j = (j-1) & b) {
if (bits[j] & 1) ans -= sum0[(b^j) | c];
else ans += sum0[(b^j) | c];
}
ans += sum0[b | c];
}
else {
for (j = c; j > 0; j = (j-1) & c) ans += S[j | b]-'0';
ans += S[b]-'0';
}
printf("%d\n",ans);
}
return 0;
}
Compilation message (stderr)
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %s",&L,&Q,S);
~~~~~^~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",T);
~~~~~^~~~~~~~
# | 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... |