Submission #42370

#TimeUsernameProblemLanguageResultExecution timeMemory
42370RezwanArefin01Snake Escaping (JOI18_snake_escaping)C++14
5 / 100
2039 ms36952 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; ll dp[1 << 20], ans; string b, s; int l, q; void recurr1(int i, int num, int tot) { if(i == s.size()) { if(tot & 1) ans -= dp[num]; else ans += dp[num]; return; } if(s[i] == '0') { recurr1(i + 1, num << 1, tot); } else if(s[i] == '?') { recurr1(i + 1, num << 1 | 1, tot); } else { recurr1(i + 1, num << 1 | 1, tot); recurr1(i + 1, num << 1, tot + 1); } } int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(0); cin.tie(0); cin >> l >> q >> b; for(int i = 0; i < (1 << l); i++) { dp[i] = b[i] - '0'; } for(int i = 0; i < l; i++) { for(int j = 0; j < (1 << l); j++) { if(j >> i & 1) dp[j] += dp[j ^ (1 << i)]; } } while(q--) { cin >> s; int n0 = 0, n1 = 0, nw0t = 0; for(char c : s) { n0 += c == '0'; n1 += c == '1'; nw0t += c == '?'; } if(n1 == 0) { int num = 0; for(char c : s) num = (num << 1) + (c == '?'); cout << dp[num] << endl; } else if(nw0t == 0) { int num = 0; for(char c : s) num = (num << 1) + (c == '1'); cout << b[num] << endl; } else { //if(n1 <= n0 && n1 <= nw0t) { ans = 0; recurr1(0, 0, 0); //} cout << ans << endl; } } }

Compilation message (stderr)

snake_escaping.cpp: In function 'void recurr1(int, int, int)':
snake_escaping.cpp:11:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(i == s.size()) {
       ^
#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...