//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
/*
ID: samikgo1
TASK:
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef complex<ll> point;
#define X real()
#define Y imag()
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
//#define f first
//#define s second
//#define x first
//#define y second
const ll INF = 1e17;
const ll sqrtn = 440;
const ll modulo = 1e9+7;
const ll siz = 262144;
const ll hashp = 923981238;
const ll hashm = 932439994;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int ll
int memo[1594323];
char str[1048576];
char queries[1000000][20];
int ansq[1000000];
int get(char *s,int i){
if(memo[i]!=-1)return memo[i];
int p = 1;
for(int x=0;x<13;x++) {
if (s[x] == '?') {
s[x] = '0';
int ans = get(s, i + p);
s[x] = '1';
ans += get(s, i + 2 * p);
s[x] = '?';
return memo[i] = ans;
}
p*=3;
}
}
int getidx(const char *s){
int p = 1;
int ans = 0;
for(int a=0;a<13;a++){
if(s[a]=='0')ans+=p;
else if(s[a]=='1')ans+=p*2;
p*=3;
}
return ans;
}
inline bool match(string a,const char *b){
for(int i=0;i<7;i++)if(b[i]!='?' and a[i]!=b[i])return false;
return true;
}
void solve() {
int l,q;
cin >> l >> q;
for(int i=0;i<(1<<l);i++)cin >> str[i];
for(int i=0;i<(1<<l);i++)str[i]-='0';
for(int i=1;i<=q;i++){
string s;cin>>s;
for(int x=0;x<20-l;x++)s.insert(s.begin(),'0');
for(int x=0;x<20;x++)queries[i][x] = s[x];
}
for(int modifier=0;modifier<(1<<7);modifier++){
for(int&i:memo)i=-1;
for(int i=0;i<(1<<13);i++)memo[getidx(bitset<13>(i).to_string().c_str())]=str[(modifier<<13)+i];
for(int i=1;i<=q;i++){
if(!match(bitset<7>(modifier).to_string(),queries[i]))continue;
ansq[i]+=get(queries[i]+7,getidx(queries[i]+7));
}
}
for(int i=1;i<=q;i++)cout<<ansq[i]<<'\n';
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("cses.fi.txt","r",stdin);
// freopen(".out","w",stdout);
// int t;
// cin >> t;
// while(t--)
solve();
}
Compilation message
snake_escaping.cpp: In function 'll get(char*, ll)':
snake_escaping.cpp:54:1: warning: control reaches end of non-void function [-Wreturn-type]
54 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
16472 KB |
Output is correct |
2 |
Correct |
124 ms |
16476 KB |
Output is correct |
3 |
Correct |
130 ms |
16564 KB |
Output is correct |
4 |
Correct |
130 ms |
16564 KB |
Output is correct |
5 |
Correct |
124 ms |
16476 KB |
Output is correct |
6 |
Correct |
135 ms |
16560 KB |
Output is correct |
7 |
Correct |
122 ms |
16476 KB |
Output is correct |
8 |
Correct |
128 ms |
16568 KB |
Output is correct |
9 |
Correct |
121 ms |
16476 KB |
Output is correct |
10 |
Correct |
131 ms |
16728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
16472 KB |
Output is correct |
2 |
Correct |
124 ms |
16476 KB |
Output is correct |
3 |
Correct |
130 ms |
16564 KB |
Output is correct |
4 |
Correct |
130 ms |
16564 KB |
Output is correct |
5 |
Correct |
124 ms |
16476 KB |
Output is correct |
6 |
Correct |
135 ms |
16560 KB |
Output is correct |
7 |
Correct |
122 ms |
16476 KB |
Output is correct |
8 |
Correct |
128 ms |
16568 KB |
Output is correct |
9 |
Correct |
121 ms |
16476 KB |
Output is correct |
10 |
Correct |
131 ms |
16728 KB |
Output is correct |
11 |
Execution timed out |
2055 ms |
52052 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
16472 KB |
Output is correct |
2 |
Correct |
124 ms |
16476 KB |
Output is correct |
3 |
Correct |
130 ms |
16564 KB |
Output is correct |
4 |
Correct |
130 ms |
16564 KB |
Output is correct |
5 |
Correct |
124 ms |
16476 KB |
Output is correct |
6 |
Correct |
135 ms |
16560 KB |
Output is correct |
7 |
Correct |
122 ms |
16476 KB |
Output is correct |
8 |
Correct |
128 ms |
16568 KB |
Output is correct |
9 |
Correct |
121 ms |
16476 KB |
Output is correct |
10 |
Correct |
131 ms |
16728 KB |
Output is correct |
11 |
Execution timed out |
2055 ms |
52052 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
16472 KB |
Output is correct |
2 |
Correct |
124 ms |
16476 KB |
Output is correct |
3 |
Correct |
130 ms |
16564 KB |
Output is correct |
4 |
Correct |
130 ms |
16564 KB |
Output is correct |
5 |
Correct |
124 ms |
16476 KB |
Output is correct |
6 |
Correct |
135 ms |
16560 KB |
Output is correct |
7 |
Correct |
122 ms |
16476 KB |
Output is correct |
8 |
Correct |
128 ms |
16568 KB |
Output is correct |
9 |
Correct |
121 ms |
16476 KB |
Output is correct |
10 |
Correct |
131 ms |
16728 KB |
Output is correct |
11 |
Correct |
407 ms |
22888 KB |
Output is correct |
12 |
Correct |
478 ms |
23140 KB |
Output is correct |
13 |
Correct |
365 ms |
22876 KB |
Output is correct |
14 |
Correct |
445 ms |
22880 KB |
Output is correct |
15 |
Correct |
854 ms |
23140 KB |
Output is correct |
16 |
Correct |
533 ms |
22916 KB |
Output is correct |
17 |
Correct |
527 ms |
23100 KB |
Output is correct |
18 |
Correct |
331 ms |
23136 KB |
Output is correct |
19 |
Correct |
309 ms |
22884 KB |
Output is correct |
20 |
Correct |
477 ms |
23124 KB |
Output is correct |
21 |
Correct |
680 ms |
22876 KB |
Output is correct |
22 |
Correct |
529 ms |
23124 KB |
Output is correct |
23 |
Correct |
298 ms |
23140 KB |
Output is correct |
24 |
Correct |
417 ms |
22876 KB |
Output is correct |
25 |
Correct |
559 ms |
22876 KB |
Output is correct |
26 |
Correct |
248 ms |
22728 KB |
Output is correct |
27 |
Correct |
427 ms |
22896 KB |
Output is correct |
28 |
Correct |
339 ms |
22884 KB |
Output is correct |
29 |
Correct |
381 ms |
22864 KB |
Output is correct |
30 |
Correct |
399 ms |
23124 KB |
Output is correct |
31 |
Correct |
348 ms |
23120 KB |
Output is correct |
32 |
Correct |
535 ms |
22972 KB |
Output is correct |
33 |
Correct |
516 ms |
22876 KB |
Output is correct |
34 |
Correct |
272 ms |
22864 KB |
Output is correct |
35 |
Correct |
536 ms |
22880 KB |
Output is correct |
36 |
Correct |
544 ms |
22876 KB |
Output is correct |
37 |
Correct |
540 ms |
23104 KB |
Output is correct |
38 |
Correct |
542 ms |
22856 KB |
Output is correct |
39 |
Correct |
521 ms |
23124 KB |
Output is correct |
40 |
Correct |
557 ms |
22984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
16472 KB |
Output is correct |
2 |
Correct |
124 ms |
16476 KB |
Output is correct |
3 |
Correct |
130 ms |
16564 KB |
Output is correct |
4 |
Correct |
130 ms |
16564 KB |
Output is correct |
5 |
Correct |
124 ms |
16476 KB |
Output is correct |
6 |
Correct |
135 ms |
16560 KB |
Output is correct |
7 |
Correct |
122 ms |
16476 KB |
Output is correct |
8 |
Correct |
128 ms |
16568 KB |
Output is correct |
9 |
Correct |
121 ms |
16476 KB |
Output is correct |
10 |
Correct |
131 ms |
16728 KB |
Output is correct |
11 |
Execution timed out |
2055 ms |
52052 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |