Submission #1102177

# Submission time Handle Problem Language Result Execution time Memory
1102177 2024-10-17T15:37:26 Z trandangquang Snake Escaping (JOI18_snake_escaping) C++14
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

#define task "test"
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define bit(s, i) (((s) >> (i)) & 1)
#define ii pair <int, int>
#define fi first
#define se second
#define ll long long
#define eb emplace_back
#define pb push_back
#define __builtin_popcount __builtin_popcountll

void solve();

int32_t main() {
    if(fopen(task".inp", "r")) {
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
	}
	cin.tie(0)->sync_with_stdio(0);

    solve();
}

const int LG = 20;

int l, q, dp1[1<<LG], dp2[1<<LG], cnt[1<<LG], cntbit[1<<LG];
string s;

void solve() {
    cin >> l >> q >> s;
    FOR(i, 0, (1<<l)-1) {
        dp1[i] += s[i]-'0';
        dp2[i] += s[i]-'0';
        cnt[i] += s[i]-'0';
    }

    FOR(mask, 0, (1<<l)-1) cntbit[mask] = __builtin_popcount(mask);
    FOR(i, 0, l-1) {
        FOR(mask, 0, (1<<l)-1) {
            if(bit(mask, i)) {
                dp1[mask] += dp1[mask^(1<<i)];
            }
            else {
                dp2[mask] += dp2[mask^(1<<i)];
            }
        }
    }

    FOR(i, 1, q) {
        string t; cin >> t;
        reverse(all(t));

        int qm = 0, one = 0, zero = 0;
        FOR(j, 0, l-1) {
            if(t[j] == '?') qm |= (1<<j);
            else if(t[j] == '1') one |= (1<<j);
            else zero |= (1<<j);
        }

        if(cntbit[qm] <= l/3){
            int ans = 0;
            for(int mask = qm;; mask = (mask-1)&qm) {
                ans += cnt[mask | one];
                if(mask == 0) break;
            }
            cout << ans << '\n';
        }
        else if(cntbit[one] <= l/3) {
            int ans = 0;
            for(int mask = one;; mask = (mask-1)&one) {
                if((cnt[one] - cnt[mask]) & 1) ans = ans - dp1[mask | qm];
                else ans = ans + dp1[mask | qm];
                if(mask == 0) break;
            }
            cout << ans << '\n';
        }
        else {
            int ans = 0;
            for(int mask = zero;; mask = (mask-1)&zero) {
                if(cnt[mask] & 1) ans = ans - dp2[one | mask];
                else ans = ans + dp2[one | mask];
                if(mask == 0) break;
            }
            cout << ans << '\n';
        }
    }
}

Compilation message

snake_escaping.cpp: In function 'int32_t main()':
snake_escaping.cpp:23:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:24:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -