// __builtin_popcount(x) broj bitova
// __builtin_popcountll(x)
// __builtin_clz(x) vodece nule
// __builtin_clzll(x)
// __builtin_ctz(x) nule na pocetku
// __builtin_ctzll(x)
// 2000000011
// 2000000033
#include "bits/stdc++.h"
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll int
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) ((ll)(a.size()))
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define pi 3.14159265358979323846
#define here cerr<<"=============================================================================\n"
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define ceri2(a,l,r,n,m) {for(ll i = l;i<=r;i++){for(ll j = n;j<=m;j++) cerr<<a[i][j]<< " ";cerr<<endl;}}
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
//#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
using namespace __gnu_pbds;
template<typename T> using vc = vector<T>;
template<typename T> using vvc = vc<vc<T>>;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
return uniform_int_distribution<ll>(l,r)(rng);
}
void setIO(string inoutname)
{
freopen((inoutname+".in").c_str(),"r",stdin);
freopen((inoutname+".out").c_str(),"w",stdout);
}
#define mod 1
ll gcd(ll a, ll b)
{
if(b==0) return a;
if(a==0) return b;
if(a>=b) return gcd(a%b,b);
return gcd(a,b%a);
}
ll lcm(ll a,ll b){
return (a/gcd(a,b))*b;
}
ll add(ll x,ll y){
x+=y;
if(x<0){
x%=mod;
x+=mod;
if(x==mod) x = 0;
}else{
if(x>=mod) x%=mod;
}
return x;
}
ll mul(ll a,ll b){
ll ans = (a*b)%mod;
if(ans<0) ans+=mod;
return ans;
}
ll po(ll x,ll y){
if(y==0) return 1LL;
ll ans = po(x,y/2);
ans = mul(ans,ans);
if(y&1) ans = mul(ans,x);
return ans;
}
ll inv(ll x){return po(x,mod-2);}
#define maxn 2000005
ll n,q;
ll l;
ll sub[maxn],sup[maxn],btc[maxn];
ll s[maxn];
void tc(){
cin >> l >> q;
n = (1<<l)-1;
string ss; cin >> ss;
for(ll i = 0;i<=n;i++) s[i] = (ss[i]-'0');
for(ll i = 0;i<=n;i++){
btc[i] = __builtin_popcountll(i);
sub[i] = sup[i] = s[i];
}
for(ll j = 0;j<l;j++){
for(ll i = 0;i<=n;i++){
if(((1<<j)&i)==0){
sup[i]+=sup[i^(1<<j)];
}else{
sub[i]+=sub[i^(1<<j)];
}
}
}
while(q--){
char ss[l+1]; scanf("%s",ss);
ll a = 0,b = 0,c = 0;
ll ca = 0,cb = 0,cc = 0;
for(ll i = 0;i<l;i++){
ll k = l-i-1;
if(ss[i]=='0'){
a|=(1<<k); ca++;
}else if(ss[i]=='1'){
b|=(1<<k); cb++;
}else{
c|=(1<<k); cc++;
}
}
ll mc = min({ca,cb,cc});
ll ans = 0;
if(ca == mc){
for(ll mask = a;mask!=0;mask=a&(mask-1)){
ans+=(1-2*((btc[mask])&1))*sup[b|mask];
}
ans+=sup[b];
}else if(cb==mc){
for(ll mask = b;mask!=0;mask=b&(mask-1)){
ans+=(1-2*((btc[mask^b])&1))*sub[c|(mask)];
}
ans += (1-2*((btc[b])&1))*sub[c];
}else{
for(ll mask = c;mask!=0;mask=c&(mask-1)){
ans+=s[b|mask];
}
ans+=s[b];
}
printf("%ld",ans);
printf("\n");
}
}
int main(){
//setIO("lol");
int t; t = 1;
while(t--){
tc();
}
return 0;
}
Compilation message
snake_escaping.cpp: In function 'void tc()':
snake_escaping.cpp:143:19: warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'int' [-Wformat=]
143 | printf("%ld",ans);
| ~~^ ~~~
| | |
| | int
| long int
| %d
snake_escaping.cpp: In function 'void setIO(std::string)':
snake_escaping.cpp:50:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | freopen((inoutname+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:51:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | freopen((inoutname+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp: In function 'void tc()':
snake_escaping.cpp:112:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
112 | char ss[l+1]; scanf("%s",ss);
| ~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
248 ms |
4744 KB |
Output is correct |
12 |
Correct |
251 ms |
4336 KB |
Output is correct |
13 |
Correct |
279 ms |
3620 KB |
Output is correct |
14 |
Correct |
265 ms |
3688 KB |
Output is correct |
15 |
Correct |
255 ms |
4684 KB |
Output is correct |
16 |
Correct |
273 ms |
3868 KB |
Output is correct |
17 |
Correct |
297 ms |
3796 KB |
Output is correct |
18 |
Correct |
212 ms |
5836 KB |
Output is correct |
19 |
Correct |
237 ms |
2716 KB |
Output is correct |
20 |
Correct |
261 ms |
4336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
248 ms |
4744 KB |
Output is correct |
12 |
Correct |
251 ms |
4336 KB |
Output is correct |
13 |
Correct |
279 ms |
3620 KB |
Output is correct |
14 |
Correct |
265 ms |
3688 KB |
Output is correct |
15 |
Correct |
255 ms |
4684 KB |
Output is correct |
16 |
Correct |
273 ms |
3868 KB |
Output is correct |
17 |
Correct |
297 ms |
3796 KB |
Output is correct |
18 |
Correct |
212 ms |
5836 KB |
Output is correct |
19 |
Correct |
237 ms |
2716 KB |
Output is correct |
20 |
Correct |
261 ms |
4336 KB |
Output is correct |
21 |
Correct |
266 ms |
4820 KB |
Output is correct |
22 |
Correct |
275 ms |
5068 KB |
Output is correct |
23 |
Correct |
305 ms |
4044 KB |
Output is correct |
24 |
Correct |
332 ms |
3776 KB |
Output is correct |
25 |
Correct |
276 ms |
5852 KB |
Output is correct |
26 |
Correct |
337 ms |
4424 KB |
Output is correct |
27 |
Correct |
323 ms |
4300 KB |
Output is correct |
28 |
Correct |
218 ms |
6884 KB |
Output is correct |
29 |
Correct |
262 ms |
2948 KB |
Output is correct |
30 |
Correct |
281 ms |
4940 KB |
Output is correct |
31 |
Correct |
316 ms |
4788 KB |
Output is correct |
32 |
Correct |
321 ms |
4812 KB |
Output is correct |
33 |
Correct |
282 ms |
3660 KB |
Output is correct |
34 |
Correct |
324 ms |
3916 KB |
Output is correct |
35 |
Correct |
329 ms |
4288 KB |
Output is correct |
36 |
Correct |
234 ms |
2764 KB |
Output is correct |
37 |
Correct |
260 ms |
4888 KB |
Output is correct |
38 |
Correct |
279 ms |
2768 KB |
Output is correct |
39 |
Correct |
299 ms |
4020 KB |
Output is correct |
40 |
Correct |
319 ms |
3800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
73 ms |
19516 KB |
Output is correct |
12 |
Correct |
68 ms |
20184 KB |
Output is correct |
13 |
Correct |
80 ms |
20040 KB |
Output is correct |
14 |
Correct |
82 ms |
20104 KB |
Output is correct |
15 |
Correct |
71 ms |
20144 KB |
Output is correct |
16 |
Correct |
84 ms |
20100 KB |
Output is correct |
17 |
Correct |
85 ms |
20056 KB |
Output is correct |
18 |
Correct |
69 ms |
20308 KB |
Output is correct |
19 |
Correct |
75 ms |
19924 KB |
Output is correct |
20 |
Correct |
69 ms |
20188 KB |
Output is correct |
21 |
Correct |
87 ms |
20192 KB |
Output is correct |
22 |
Correct |
83 ms |
20036 KB |
Output is correct |
23 |
Correct |
84 ms |
20032 KB |
Output is correct |
24 |
Correct |
89 ms |
20072 KB |
Output is correct |
25 |
Correct |
85 ms |
20060 KB |
Output is correct |
26 |
Correct |
62 ms |
20024 KB |
Output is correct |
27 |
Correct |
70 ms |
20156 KB |
Output is correct |
28 |
Correct |
71 ms |
19932 KB |
Output is correct |
29 |
Correct |
81 ms |
20172 KB |
Output is correct |
30 |
Correct |
73 ms |
20032 KB |
Output is correct |
31 |
Correct |
69 ms |
19980 KB |
Output is correct |
32 |
Correct |
89 ms |
20140 KB |
Output is correct |
33 |
Correct |
83 ms |
20188 KB |
Output is correct |
34 |
Correct |
64 ms |
20000 KB |
Output is correct |
35 |
Correct |
79 ms |
20148 KB |
Output is correct |
36 |
Correct |
78 ms |
20072 KB |
Output is correct |
37 |
Correct |
81 ms |
20084 KB |
Output is correct |
38 |
Correct |
78 ms |
20072 KB |
Output is correct |
39 |
Correct |
79 ms |
20056 KB |
Output is correct |
40 |
Correct |
78 ms |
20148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
248 ms |
4744 KB |
Output is correct |
12 |
Correct |
251 ms |
4336 KB |
Output is correct |
13 |
Correct |
279 ms |
3620 KB |
Output is correct |
14 |
Correct |
265 ms |
3688 KB |
Output is correct |
15 |
Correct |
255 ms |
4684 KB |
Output is correct |
16 |
Correct |
273 ms |
3868 KB |
Output is correct |
17 |
Correct |
297 ms |
3796 KB |
Output is correct |
18 |
Correct |
212 ms |
5836 KB |
Output is correct |
19 |
Correct |
237 ms |
2716 KB |
Output is correct |
20 |
Correct |
261 ms |
4336 KB |
Output is correct |
21 |
Correct |
266 ms |
4820 KB |
Output is correct |
22 |
Correct |
275 ms |
5068 KB |
Output is correct |
23 |
Correct |
305 ms |
4044 KB |
Output is correct |
24 |
Correct |
332 ms |
3776 KB |
Output is correct |
25 |
Correct |
276 ms |
5852 KB |
Output is correct |
26 |
Correct |
337 ms |
4424 KB |
Output is correct |
27 |
Correct |
323 ms |
4300 KB |
Output is correct |
28 |
Correct |
218 ms |
6884 KB |
Output is correct |
29 |
Correct |
262 ms |
2948 KB |
Output is correct |
30 |
Correct |
281 ms |
4940 KB |
Output is correct |
31 |
Correct |
316 ms |
4788 KB |
Output is correct |
32 |
Correct |
321 ms |
4812 KB |
Output is correct |
33 |
Correct |
282 ms |
3660 KB |
Output is correct |
34 |
Correct |
324 ms |
3916 KB |
Output is correct |
35 |
Correct |
329 ms |
4288 KB |
Output is correct |
36 |
Correct |
234 ms |
2764 KB |
Output is correct |
37 |
Correct |
260 ms |
4888 KB |
Output is correct |
38 |
Correct |
279 ms |
2768 KB |
Output is correct |
39 |
Correct |
299 ms |
4020 KB |
Output is correct |
40 |
Correct |
319 ms |
3800 KB |
Output is correct |
41 |
Correct |
73 ms |
19516 KB |
Output is correct |
42 |
Correct |
68 ms |
20184 KB |
Output is correct |
43 |
Correct |
80 ms |
20040 KB |
Output is correct |
44 |
Correct |
82 ms |
20104 KB |
Output is correct |
45 |
Correct |
71 ms |
20144 KB |
Output is correct |
46 |
Correct |
84 ms |
20100 KB |
Output is correct |
47 |
Correct |
85 ms |
20056 KB |
Output is correct |
48 |
Correct |
69 ms |
20308 KB |
Output is correct |
49 |
Correct |
75 ms |
19924 KB |
Output is correct |
50 |
Correct |
69 ms |
20188 KB |
Output is correct |
51 |
Correct |
87 ms |
20192 KB |
Output is correct |
52 |
Correct |
83 ms |
20036 KB |
Output is correct |
53 |
Correct |
84 ms |
20032 KB |
Output is correct |
54 |
Correct |
89 ms |
20072 KB |
Output is correct |
55 |
Correct |
85 ms |
20060 KB |
Output is correct |
56 |
Correct |
62 ms |
20024 KB |
Output is correct |
57 |
Correct |
70 ms |
20156 KB |
Output is correct |
58 |
Correct |
71 ms |
19932 KB |
Output is correct |
59 |
Correct |
81 ms |
20172 KB |
Output is correct |
60 |
Correct |
73 ms |
20032 KB |
Output is correct |
61 |
Correct |
69 ms |
19980 KB |
Output is correct |
62 |
Correct |
89 ms |
20140 KB |
Output is correct |
63 |
Correct |
83 ms |
20188 KB |
Output is correct |
64 |
Correct |
64 ms |
20000 KB |
Output is correct |
65 |
Correct |
79 ms |
20148 KB |
Output is correct |
66 |
Correct |
78 ms |
20072 KB |
Output is correct |
67 |
Correct |
81 ms |
20084 KB |
Output is correct |
68 |
Correct |
78 ms |
20072 KB |
Output is correct |
69 |
Correct |
79 ms |
20056 KB |
Output is correct |
70 |
Correct |
78 ms |
20148 KB |
Output is correct |
71 |
Correct |
447 ms |
23440 KB |
Output is correct |
72 |
Correct |
425 ms |
23612 KB |
Output is correct |
73 |
Correct |
547 ms |
22204 KB |
Output is correct |
74 |
Correct |
641 ms |
22404 KB |
Output is correct |
75 |
Correct |
437 ms |
24512 KB |
Output is correct |
76 |
Correct |
736 ms |
22992 KB |
Output is correct |
77 |
Correct |
713 ms |
22764 KB |
Output is correct |
78 |
Correct |
329 ms |
26556 KB |
Output is correct |
79 |
Correct |
403 ms |
20412 KB |
Output is correct |
80 |
Correct |
474 ms |
23640 KB |
Output is correct |
81 |
Correct |
530 ms |
23440 KB |
Output is correct |
82 |
Correct |
629 ms |
22528 KB |
Output is correct |
83 |
Correct |
422 ms |
21692 KB |
Output is correct |
84 |
Correct |
771 ms |
22476 KB |
Output is correct |
85 |
Correct |
712 ms |
22764 KB |
Output is correct |
86 |
Correct |
320 ms |
20432 KB |
Output is correct |
87 |
Correct |
406 ms |
23656 KB |
Output is correct |
88 |
Correct |
433 ms |
20452 KB |
Output is correct |
89 |
Correct |
526 ms |
22248 KB |
Output is correct |
90 |
Correct |
524 ms |
22460 KB |
Output is correct |
91 |
Correct |
444 ms |
21660 KB |
Output is correct |
92 |
Correct |
775 ms |
22744 KB |
Output is correct |
93 |
Correct |
701 ms |
22732 KB |
Output is correct |
94 |
Correct |
319 ms |
20484 KB |
Output is correct |
95 |
Correct |
615 ms |
22596 KB |
Output is correct |
96 |
Correct |
643 ms |
22600 KB |
Output is correct |
97 |
Correct |
619 ms |
22600 KB |
Output is correct |
98 |
Correct |
658 ms |
22556 KB |
Output is correct |
99 |
Correct |
611 ms |
22568 KB |
Output is correct |
100 |
Correct |
622 ms |
22592 KB |
Output is correct |