Submission #208825

#TimeUsernameProblemLanguageResultExecution timeMemory
208825SiberianSnake Escaping (JOI18_snake_escaping)C++14
0 / 100
7 ms376 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; #define all(x) x.begin(), x.end() template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;} template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;} int n, q; string s; void read() { cin >> n >> q; cin >> s; } pair<int, int> get_mask() { string s; cin >> s; int mask = 0; int must = 0; for (int i = 0; i < n; i++) { mask *= 2; if (s[i] != '0') mask++; must *= 2; if (s[i] == '1') must++; } return {mask, must}; } void build() { } bool check_submask(int mask, int submask) { return (mask & submask) == submask; } void solve() { auto x = get_mask(); int mask = x.first, must = x.second; int ans = 0; //cout << "mask = " << mask << endl; for (int i = mask; i >= 0; i = (i - 1) & mask) { if (s[i] == '1' && check_submask(i, must)) ++ans; if (i == 0) break; } cout << ans << "\n"; } void run() { build(); while (q--) { solve(); } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); read(); run(); return 0; }
#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...