Submission #42369

#TimeUsernameProblemLanguageResultExecution timeMemory
42369RezwanArefin01Snake Escaping (JOI18_snake_escaping)C++14
5 / 100
2044 ms12836 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; ll dp[1 << 20]; string b; int main(int argc, char const *argv[]) { int l, q; scanf("%d %d", &l, &q); cin >> 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--) { string s; 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 { vector<int> id; int basic = 0; for(int i = 0; i < s.size(); i++) { if(s[i] == '1') id.push_back(s.size() - 1 - i); if(s[i] == '?') s[i] = '1'; basic = (basic << 1) + (s[i] == '1'); } ll ans = 0; for(int mask = 0; mask < (1 << id.size()); mask++) { int cnt = __builtin_popcount(mask); int num = basic; for(int i = 0; i < id.size(); i++) { if(mask >> i & 1) num -= (1 << id[i]); } if(cnt & 1) ans -= dp[num]; else ans += dp[num]; //cout << bitset<4>(num).to_string() << endl; } cout << ans << endl; } } }

Compilation message (stderr)

snake_escaping.cpp: In function 'int main(int, const char**)':
snake_escaping.cpp:43:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = 0; i < s.size(); i++) {
                     ^
snake_escaping.cpp:52:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < id.size(); i++) {
                      ^
snake_escaping.cpp:11:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int l, q; scanf("%d %d", &l, &q);
                                  ^
#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...