Submission #455178

# Submission time Handle Problem Language Result Execution time Memory
455178 2021-08-05T15:50:46 Z Killer2501 Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
1333 ms 65536 KB
#include<bits/stdc++.h>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define pii pair<ll, pll>
using namespace std;
using ll = int;
const int  N = 2e6+55;
const ll mod = 1e9+7;
const ll mod1 = 1e9+1;
const ll base = 311;
const ll base1 = 331;
ll m, n, t, k, a[N], tong, b[N], dp[N], c[N], lab[N], cnt, ans, h[N], d[N];
priority_queue< pll, vector<pll>, greater<pll> > pq;
string s;
vector<ll> adj[N];
vector<pll> e;
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}


void f2(ll x)
{
    while(x)
    {
        cout << x % 2;
        x /= 2;
    }
    cout << '\n';
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> s;

    for(int i = 0; i < (1 << n); i ++)
    {
        a[i] = b[i] = c[i] = s[i] - '0';
    }
    for(int j = 0; j < n; j ++)
    {
        for(int i = 0; i < (1<<n); i ++)
        {
            if((i >> j) & 1)b[i] += b[i^(1<<j)];
            else a[i] += a[i^(1<<j)];
        }
    }
    //cout << b[0] << '\n';
    while(m -- > 0)
    {
        cin >> s;
        reverse(s.begin(), s.end());
        ll c0 = 0, c1 = 0, c2 = 0;
        for(int i = 0; i < n; i ++)
        {
            if(s[i] == '0')++c0;
            else if(s[i] == '1')++c1;
            else ++c2;
        }
        ll x = 0, y = 0;
        ans = 0;
        if(c0 == min(min(c0, c1), c2))
        {
            for(int i = 0; i < n; i ++)
            {
                if(s[i] == '0')x |= (1<<i);
                if(s[i] == '1')y |= (1<<i);
            }
            for(int i = x; ; i = (i - 1) & x)
            {
                if(__builtin_popcount(i) & 1)ans -= a[i+y];
                else ans += a[i+y];
                if(!i)break;
            }
        }
        else if(c1 == min(min(c0, c1), c2))
        {
            for(int i = 0; i < n; i ++)
            {
                if(s[i] == '1')x |= (1<<i);
                if(s[i] != '0')y |= (1<<i);
            }
            //cout << x <<" "<< y << '\n';
            for(int i = x; ; i = (i - 1) & x)
            {
                if(__builtin_popcount(i) & 1)ans -= b[y-i];
                else ans += b[y-i];
                if(!i)break;
            }

        }
        else
        {
            for(int i = 0; i < n; i ++)
            {
                if(s[i] == '?')x |= (1<<i);
                if(s[i] == '1')y |= (1<<i);
            }
            for(int i = x; ; i = (i - 1) & x)
            {
                ans += c[i+y];
                if(!i)break;
            }
        }
        cout << ans << '\n';
    }
}
/*
3 5
12345678
000
0??
1?0
?11
???
*/
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47340 KB Output is correct
2 Correct 25 ms 47296 KB Output is correct
3 Correct 26 ms 47224 KB Output is correct
4 Correct 25 ms 47308 KB Output is correct
5 Correct 26 ms 47336 KB Output is correct
6 Correct 26 ms 47348 KB Output is correct
7 Correct 27 ms 47240 KB Output is correct
8 Correct 25 ms 47308 KB Output is correct
9 Correct 30 ms 47240 KB Output is correct
10 Correct 26 ms 47216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47340 KB Output is correct
2 Correct 25 ms 47296 KB Output is correct
3 Correct 26 ms 47224 KB Output is correct
4 Correct 25 ms 47308 KB Output is correct
5 Correct 26 ms 47336 KB Output is correct
6 Correct 26 ms 47348 KB Output is correct
7 Correct 27 ms 47240 KB Output is correct
8 Correct 25 ms 47308 KB Output is correct
9 Correct 30 ms 47240 KB Output is correct
10 Correct 26 ms 47216 KB Output is correct
11 Correct 292 ms 62108 KB Output is correct
12 Correct 326 ms 61728 KB Output is correct
13 Correct 360 ms 61088 KB Output is correct
14 Correct 426 ms 61072 KB Output is correct
15 Correct 337 ms 62064 KB Output is correct
16 Correct 371 ms 61196 KB Output is correct
17 Correct 380 ms 61152 KB Output is correct
18 Correct 239 ms 63076 KB Output is correct
19 Correct 275 ms 59972 KB Output is correct
20 Correct 317 ms 61764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47340 KB Output is correct
2 Correct 25 ms 47296 KB Output is correct
3 Correct 26 ms 47224 KB Output is correct
4 Correct 25 ms 47308 KB Output is correct
5 Correct 26 ms 47336 KB Output is correct
6 Correct 26 ms 47348 KB Output is correct
7 Correct 27 ms 47240 KB Output is correct
8 Correct 25 ms 47308 KB Output is correct
9 Correct 30 ms 47240 KB Output is correct
10 Correct 26 ms 47216 KB Output is correct
11 Correct 292 ms 62108 KB Output is correct
12 Correct 326 ms 61728 KB Output is correct
13 Correct 360 ms 61088 KB Output is correct
14 Correct 426 ms 61072 KB Output is correct
15 Correct 337 ms 62064 KB Output is correct
16 Correct 371 ms 61196 KB Output is correct
17 Correct 380 ms 61152 KB Output is correct
18 Correct 239 ms 63076 KB Output is correct
19 Correct 275 ms 59972 KB Output is correct
20 Correct 317 ms 61764 KB Output is correct
21 Correct 317 ms 65068 KB Output is correct
22 Correct 388 ms 65300 KB Output is correct
23 Correct 439 ms 64320 KB Output is correct
24 Correct 531 ms 64152 KB Output is correct
25 Correct 385 ms 65536 KB Output is correct
26 Correct 454 ms 64572 KB Output is correct
27 Correct 458 ms 64648 KB Output is correct
28 Correct 277 ms 65536 KB Output is correct
29 Correct 315 ms 63124 KB Output is correct
30 Correct 334 ms 65232 KB Output is correct
31 Correct 439 ms 65128 KB Output is correct
32 Correct 463 ms 65164 KB Output is correct
33 Correct 350 ms 63972 KB Output is correct
34 Correct 496 ms 64064 KB Output is correct
35 Correct 452 ms 64524 KB Output is correct
36 Correct 283 ms 63136 KB Output is correct
37 Correct 358 ms 65116 KB Output is correct
38 Correct 328 ms 63044 KB Output is correct
39 Correct 405 ms 64236 KB Output is correct
40 Correct 470 ms 64152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47340 KB Output is correct
2 Correct 25 ms 47296 KB Output is correct
3 Correct 26 ms 47224 KB Output is correct
4 Correct 25 ms 47308 KB Output is correct
5 Correct 26 ms 47336 KB Output is correct
6 Correct 26 ms 47348 KB Output is correct
7 Correct 27 ms 47240 KB Output is correct
8 Correct 25 ms 47308 KB Output is correct
9 Correct 30 ms 47240 KB Output is correct
10 Correct 26 ms 47216 KB Output is correct
11 Correct 105 ms 63068 KB Output is correct
12 Correct 92 ms 63156 KB Output is correct
13 Correct 99 ms 63004 KB Output is correct
14 Correct 120 ms 62936 KB Output is correct
15 Correct 89 ms 63040 KB Output is correct
16 Correct 114 ms 63036 KB Output is correct
17 Correct 120 ms 62980 KB Output is correct
18 Correct 80 ms 63144 KB Output is correct
19 Correct 95 ms 62948 KB Output is correct
20 Correct 86 ms 62984 KB Output is correct
21 Correct 108 ms 63084 KB Output is correct
22 Correct 114 ms 62956 KB Output is correct
23 Correct 86 ms 62944 KB Output is correct
24 Correct 127 ms 62940 KB Output is correct
25 Correct 122 ms 63032 KB Output is correct
26 Correct 77 ms 62836 KB Output is correct
27 Correct 88 ms 63024 KB Output is correct
28 Correct 88 ms 62876 KB Output is correct
29 Correct 95 ms 62924 KB Output is correct
30 Correct 99 ms 63000 KB Output is correct
31 Correct 93 ms 62944 KB Output is correct
32 Correct 127 ms 63028 KB Output is correct
33 Correct 118 ms 62944 KB Output is correct
34 Correct 76 ms 62948 KB Output is correct
35 Correct 105 ms 62968 KB Output is correct
36 Correct 110 ms 63024 KB Output is correct
37 Correct 119 ms 62960 KB Output is correct
38 Correct 107 ms 62944 KB Output is correct
39 Correct 110 ms 62932 KB Output is correct
40 Correct 109 ms 62944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47340 KB Output is correct
2 Correct 25 ms 47296 KB Output is correct
3 Correct 26 ms 47224 KB Output is correct
4 Correct 25 ms 47308 KB Output is correct
5 Correct 26 ms 47336 KB Output is correct
6 Correct 26 ms 47348 KB Output is correct
7 Correct 27 ms 47240 KB Output is correct
8 Correct 25 ms 47308 KB Output is correct
9 Correct 30 ms 47240 KB Output is correct
10 Correct 26 ms 47216 KB Output is correct
11 Correct 292 ms 62108 KB Output is correct
12 Correct 326 ms 61728 KB Output is correct
13 Correct 360 ms 61088 KB Output is correct
14 Correct 426 ms 61072 KB Output is correct
15 Correct 337 ms 62064 KB Output is correct
16 Correct 371 ms 61196 KB Output is correct
17 Correct 380 ms 61152 KB Output is correct
18 Correct 239 ms 63076 KB Output is correct
19 Correct 275 ms 59972 KB Output is correct
20 Correct 317 ms 61764 KB Output is correct
21 Correct 317 ms 65068 KB Output is correct
22 Correct 388 ms 65300 KB Output is correct
23 Correct 439 ms 64320 KB Output is correct
24 Correct 531 ms 64152 KB Output is correct
25 Correct 385 ms 65536 KB Output is correct
26 Correct 454 ms 64572 KB Output is correct
27 Correct 458 ms 64648 KB Output is correct
28 Correct 277 ms 65536 KB Output is correct
29 Correct 315 ms 63124 KB Output is correct
30 Correct 334 ms 65232 KB Output is correct
31 Correct 439 ms 65128 KB Output is correct
32 Correct 463 ms 65164 KB Output is correct
33 Correct 350 ms 63972 KB Output is correct
34 Correct 496 ms 64064 KB Output is correct
35 Correct 452 ms 64524 KB Output is correct
36 Correct 283 ms 63136 KB Output is correct
37 Correct 358 ms 65116 KB Output is correct
38 Correct 328 ms 63044 KB Output is correct
39 Correct 405 ms 64236 KB Output is correct
40 Correct 470 ms 64152 KB Output is correct
41 Correct 105 ms 63068 KB Output is correct
42 Correct 92 ms 63156 KB Output is correct
43 Correct 99 ms 63004 KB Output is correct
44 Correct 120 ms 62936 KB Output is correct
45 Correct 89 ms 63040 KB Output is correct
46 Correct 114 ms 63036 KB Output is correct
47 Correct 120 ms 62980 KB Output is correct
48 Correct 80 ms 63144 KB Output is correct
49 Correct 95 ms 62948 KB Output is correct
50 Correct 86 ms 62984 KB Output is correct
51 Correct 108 ms 63084 KB Output is correct
52 Correct 114 ms 62956 KB Output is correct
53 Correct 86 ms 62944 KB Output is correct
54 Correct 127 ms 62940 KB Output is correct
55 Correct 122 ms 63032 KB Output is correct
56 Correct 77 ms 62836 KB Output is correct
57 Correct 88 ms 63024 KB Output is correct
58 Correct 88 ms 62876 KB Output is correct
59 Correct 95 ms 62924 KB Output is correct
60 Correct 99 ms 63000 KB Output is correct
61 Correct 93 ms 62944 KB Output is correct
62 Correct 127 ms 63028 KB Output is correct
63 Correct 118 ms 62944 KB Output is correct
64 Correct 76 ms 62948 KB Output is correct
65 Correct 105 ms 62968 KB Output is correct
66 Correct 110 ms 63024 KB Output is correct
67 Correct 119 ms 62960 KB Output is correct
68 Correct 107 ms 62944 KB Output is correct
69 Correct 110 ms 62932 KB Output is correct
70 Correct 109 ms 62944 KB Output is correct
71 Correct 487 ms 65536 KB Output is correct
72 Correct 604 ms 65536 KB Output is correct
73 Correct 804 ms 65536 KB Output is correct
74 Correct 1168 ms 65536 KB Output is correct
75 Correct 583 ms 65536 KB Output is correct
76 Correct 1172 ms 65536 KB Output is correct
77 Correct 1132 ms 65536 KB Output is correct
78 Correct 340 ms 65536 KB Output is correct
79 Correct 492 ms 65536 KB Output is correct
80 Correct 519 ms 65536 KB Output is correct
81 Correct 778 ms 65536 KB Output is correct
82 Correct 1038 ms 65536 KB Output is correct
83 Correct 525 ms 65536 KB Output is correct
84 Correct 1299 ms 65536 KB Output is correct
85 Correct 1117 ms 65536 KB Output is correct
86 Correct 350 ms 65536 KB Output is correct
87 Correct 556 ms 65536 KB Output is correct
88 Correct 483 ms 65536 KB Output is correct
89 Correct 709 ms 65536 KB Output is correct
90 Correct 706 ms 65536 KB Output is correct
91 Correct 578 ms 65536 KB Output is correct
92 Correct 1333 ms 65536 KB Output is correct
93 Correct 1254 ms 65536 KB Output is correct
94 Correct 319 ms 65536 KB Output is correct
95 Correct 950 ms 65536 KB Output is correct
96 Correct 925 ms 65536 KB Output is correct
97 Correct 933 ms 65536 KB Output is correct
98 Correct 924 ms 65536 KB Output is correct
99 Correct 910 ms 65536 KB Output is correct
100 Correct 911 ms 65536 KB Output is correct