# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1056518 | lozergam | Snake Escaping (JOI18_snake_escaping) | C++17 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define For(i, n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define debug(x) cout << #x << " : " << x << endl << flush
#define sz(x) (ll)x.size()
#define endl '\n'
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
ll n, q;
cin >> n >> q;
ll sub[1ll << n], super[1ll << n], a[1ll << n];
For(i, 1ll << n)
{
char c;
cin >> c;
a[i] = c - '0';
sub[i] = a[i];
super[i] = a[i];
}
For(i, n)
For(mask, 1ll << i)
if((1ll << i) & mask)
sub[mask] += sub[mask ^ (1ll << i)];
else
super[mask] += super[mask ^ (1ll << i)];
while(q--){
string s;cin >> s;
ll mask[3];
ll cnt[3];
For(i, 3)mask[i] = 0, cnt[i] = 0;
reverse(s.begin(), s.end());
ll tp;
For(i, sz(s))
{
if(s[i] == '0') tp = 0;
else if(s[i] == '1') tp = 1;
else tp = 2;
cnt[tp] += 1;
mask[tp] |= (1 << i);
}
ll ans = 0;
if(cnt[2] <= 7)
{
ll m = (1ll << (n + 5));
while(m != 0)
{
m = (m - 1) & mask[2];
ans += a[mask[1]|m];
}
}
else if(cnt[1] <= 7)
{
ll m = (1ll << (n + 5));
while(m != 0)
{
m = (m - 1) & mask[1];
if(__builtin_popcount(m) % 2 == 0)
ans += sub[(m ^ mask[1]) | mask[2]];
else
ans -= sub[(m ^ mask[1]) | mask[2]];
}
}
else
{
ll m = (1ll << (n + 5));
while(m != 0)
{
m = (m - 1) & mask[0];
if(__builtin_popcount(m) % 2 == 0)
ans += super[m | mask[1]];
else
ans -= super[m | mask[1]];
}
}
cout << ans << endl;
}
}
//hihiha
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |