Submission #697654

#TimeUsernameProblemLanguageResultExecution timeMemory
697654Jarif_RahmanSnake Escaping (JOI18_snake_escaping)C++17
22 / 100
408 ms26288 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const int p3[] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907}; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int L, Q; cin >> L >> Q; int* v = new int[1<<L]; for(int i = 0; i < (1<<L); i++){ char c; cin >> c; v[i] = c-'0'; } int* dp = new int[p3[L]]; fill(dp, dp+p3[L], 0); for(int i = 0; i < (1<<L); i++){ int x = 0; for(int j = 0; j < L; j++) if(i&(1<<j)) x+=p3[j]; dp[x]+=v[i]; } for(int j = 0; j < L; j++) for(int i = 0; i < p3[L]; i++){ if((i/p3[j])%3 == 2){ dp[i]+=dp[i-p3[j]*2]+dp[i-p3[j]]; } } while(Q--){ str s; cin >> s; reverse(s.begin(), s.end()); int x = 0; for(int i = 0; i < L; i++){ if(s[i] == '?') x+=p3[i]*2; else x+=(s[i]-'0')*p3[i]; } cout << dp[x] << "\n"; } }
#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...