# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
888188 | Unforgettablepl | Snake Escaping (JOI18_snake_escaping) | C++17 | 2013 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = INT64_MAX;
int arr[8192];
int ask(string &a,int perm){
int idx = 0;
for(int x=0;x<a.size();x++){
if(a[x]=='1')idx|=(1<<x);
else if(a[x]=='?'){idx|=((perm&1)<<x);perm>>=1;}
}
return arr[idx];
}
int32_t main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int L,q;
cin >> L >> q;
for(int i=0;i<(1<<L);i++){
char a;cin>>a;a-='0';
arr[i]=a;
}
map<string,int> memo;
for (int i = 0; i < q; i++) {
string a;cin>>a;
reverse(a.begin(), a.end());
if(memo.count(a)){cout<<memo[a]<<'\n';continue;}
int n = count(a.begin(), a.end(),'?');
int ans = 0;
for(int perm = 0;perm<(1<<n);perm++){
ans+=ask(a,perm);
}
cout << ans << '\n';
memo[a]=ans;
}
}
Compilation message (stderr)
# | 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... |