Submission #888189

#TimeUsernameProblemLanguageResultExecution timeMemory
888189UnforgettableplSnake Escaping (JOI18_snake_escaping)C++17
12 / 100
2063 ms65536 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = INT64_MAX; int arr[8192]; char str[13]; int L; int ask(int perm){ int idx = 0; for(int x=0;x<L;x++){ if(str[x]=='1')idx|=(1<<x); else if(str[x]=='?'){idx|=((perm&1)<<x);perm>>=1;} } return arr[idx]; } int32_t main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int 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++) { for(int j=L-1;j>=0;j--)cin>>str[j]; if(memo.count(str)){cout<<memo[str]<<'\n';continue;} int n = count(str, str+L,'?'); int ans = 0; for(int perm = 0;perm<(1<<n);perm++){ ans+=ask(perm); } cout << ans << '\n'; memo[str]=ans; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...