제출 #1128558

#제출 시각아이디문제언어결과실행 시간메모리
1128558Alihan_8Snake Escaping (JOI18_snake_escaping)C++20
22 / 100
152 ms12720 KiB
#include <bits/stdc++.h> using namespace std; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; string s; cin >> s; for ( auto &v: s ) v -= '0'; vector <int> pw(n + 1, 1); for ( int i = 1; i <= n; i++ ){ pw[i] = pw[i - 1] * 3; } vector <int> dp(pw[n]); for ( int mask = 0; mask < pw[n]; mask++ ){ bool has_q = false; for ( int i = 0; i < n; i++ ){ int b = mask / pw[i] % 3; if ( b == 2 ){ has_q = true; dp[mask] = dp[mask - pw[i]] + dp[mask - pw[i] * 2]; break; } } if ( !has_q ){ int x = 0; for ( int i = 0; i < n; i++ ){ int b = mask / pw[i] % 3; x = x * 2 + b; } dp[mask] = s[x]; } } while ( q-- ){ string t; cin >> t; int x = 0; for ( int i = 0; i < n; i++ ){ x = x + pw[i] * (t[i] == '?' ? 2 : t[i] - '0'); } 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...