Submission #697142

#TimeUsernameProblemLanguageResultExecution timeMemory
697142Jarif_RahmanSnake Escaping (JOI18_snake_escaping)C++17
12 / 100
213 ms65536 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]]; for(int i = 0; i < p3[L]; i++){ dp[i] = new int[L+1]; fill(dp[i], dp[i]+L+1, 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][0]+=v[i]; } for(int i = 0; i < p3[L]; i++) for(int j = 1; j <= L; j++){ int x = (i/p3[j-1])%3; if(x < 2) dp[i][j] = dp[i][j-1]; else dp[i][j] = dp[i-p3[j-1]*2][j-1]+dp[i-p3[j-1]][j-1]; } 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][L] << "\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...