답안 #934119

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
934119 2024-02-26T20:01:10 Z Rafi22 Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
1879 ms 24100 KB
#include <bits/stdc++.h>

//#define int long long
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int infl=1000000000000000007;
int inf=1000000007;
int mod=1000000007;
int mod1=998244353;

const bool multi=1;

const int N=(1<<20)+7;

int cnt[N];
int ile1[N];
int ile0[N];

int ans,z;
vector<int>Z,V0,V1;

void bt(int m,int i)
{
    if(i==sz(Z))
    {
        ans+=cnt[m];
        return ;
    }
    bt(m,i+1);
    bt(m^(1<<Z[i]),i+1);
}

void bt1(int m,int i,int p)
{
    if(i==sz(V1))
    {
        if(p) ans-=ile1[m^z];
        else ans+=ile1[m^z];
        return ;
    }
    bt1(m,i+1,p^1);
    bt1(m^(1<<V1[i]),i+1,p);
}

void bt2(int m,int i,int p)
{
    if(i==sz(V0))
    {
        cout<<m<<" "<<p<<" "<<ile0[m^z]<<endl;
        if(p) ans-=ile0[m^z];
        else ans+=ile0[m^z];
        return ;
    }
    bt2(m,i+1,p^1);
    bt2(m^(1<<V0[i]),i+1,p);
}

signed main()
{
    int n,q;
    cin>>n>>q;
    for(int i=0;i<(1<<n);i++)
    {
        char c;
        cin>>c;
        cnt[i]=c-'0';
        ile1[i]=cnt[i];
        ile0[(1<<n)-1-i]=cnt[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int m=0;m<(1<<n);m++)
        {
            if(m&(1<<i))
            {
                ile1[m]+=ile1[m^(1<<i)];
                ile0[m]+=ile0[m^(1<<i)];
            }
        }
    }
    while(q--)
    {
        string s;
        cin>>s;
        reverse(all(s));
        Z.clear(),V0.clear(),V1.clear();
        ans=0,z=0;
        int msk=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='?')
            {
                Z.pb(i);
                z^=(1<<i);
            }
            else if(s[i]=='0') V0.pb(i);
            else
            {
                V1.pb(i);
                msk^=(1<<i);
            }
        }
        if(sz(Z)<=6) bt(msk,0);
        else if(sz(V1)<=6) bt1(0,0,0);
        else bt2(0,0,0);
        cout<<ans<<endl;
    }


    return 0;
}

Compilation message

snake_escaping.cpp:13:10: warning: overflow in conversion from 'long int' to 'int' changes value from '1000000000000000007' to '-1486618617' [-Woverflow]
   13 | int infl=1000000000000000007;
      |          ^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4444 KB Output is correct
2 Correct 2 ms 4552 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 3 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 3 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4444 KB Output is correct
2 Correct 2 ms 4552 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 3 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 3 ms 4444 KB Output is correct
11 Correct 1599 ms 19268 KB Output is correct
12 Correct 1585 ms 19064 KB Output is correct
13 Correct 1533 ms 18084 KB Output is correct
14 Correct 1528 ms 18124 KB Output is correct
15 Correct 1726 ms 19280 KB Output is correct
16 Correct 1578 ms 18348 KB Output is correct
17 Correct 1581 ms 18236 KB Output is correct
18 Correct 1461 ms 20208 KB Output is correct
19 Correct 1474 ms 17140 KB Output is correct
20 Correct 1605 ms 19140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4444 KB Output is correct
2 Correct 2 ms 4552 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 3 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 3 ms 4444 KB Output is correct
11 Correct 1599 ms 19268 KB Output is correct
12 Correct 1585 ms 19064 KB Output is correct
13 Correct 1533 ms 18084 KB Output is correct
14 Correct 1528 ms 18124 KB Output is correct
15 Correct 1726 ms 19280 KB Output is correct
16 Correct 1578 ms 18348 KB Output is correct
17 Correct 1581 ms 18236 KB Output is correct
18 Correct 1461 ms 20208 KB Output is correct
19 Correct 1474 ms 17140 KB Output is correct
20 Correct 1605 ms 19140 KB Output is correct
21 Correct 1825 ms 22208 KB Output is correct
22 Correct 1705 ms 22308 KB Output is correct
23 Correct 1669 ms 21588 KB Output is correct
24 Correct 1700 ms 21156 KB Output is correct
25 Correct 1630 ms 23376 KB Output is correct
26 Correct 1660 ms 21692 KB Output is correct
27 Correct 1712 ms 21528 KB Output is correct
28 Correct 1543 ms 24100 KB Output is correct
29 Correct 1549 ms 20724 KB Output is correct
30 Correct 1722 ms 22288 KB Output is correct
31 Correct 1879 ms 22136 KB Output is correct
32 Correct 1765 ms 22208 KB Output is correct
33 Correct 1617 ms 21148 KB Output is correct
34 Correct 1636 ms 21116 KB Output is correct
35 Correct 1710 ms 21652 KB Output is correct
36 Correct 1503 ms 20252 KB Output is correct
37 Correct 1746 ms 22120 KB Output is correct
38 Correct 1534 ms 20196 KB Output is correct
39 Correct 1633 ms 21392 KB Output is correct
40 Correct 1674 ms 21356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4444 KB Output is correct
2 Correct 2 ms 4552 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 3 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 3 ms 4444 KB Output is correct
11 Incorrect 157 ms 15420 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4444 KB Output is correct
2 Correct 2 ms 4552 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 3 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 3 ms 4444 KB Output is correct
11 Correct 1599 ms 19268 KB Output is correct
12 Correct 1585 ms 19064 KB Output is correct
13 Correct 1533 ms 18084 KB Output is correct
14 Correct 1528 ms 18124 KB Output is correct
15 Correct 1726 ms 19280 KB Output is correct
16 Correct 1578 ms 18348 KB Output is correct
17 Correct 1581 ms 18236 KB Output is correct
18 Correct 1461 ms 20208 KB Output is correct
19 Correct 1474 ms 17140 KB Output is correct
20 Correct 1605 ms 19140 KB Output is correct
21 Correct 1825 ms 22208 KB Output is correct
22 Correct 1705 ms 22308 KB Output is correct
23 Correct 1669 ms 21588 KB Output is correct
24 Correct 1700 ms 21156 KB Output is correct
25 Correct 1630 ms 23376 KB Output is correct
26 Correct 1660 ms 21692 KB Output is correct
27 Correct 1712 ms 21528 KB Output is correct
28 Correct 1543 ms 24100 KB Output is correct
29 Correct 1549 ms 20724 KB Output is correct
30 Correct 1722 ms 22288 KB Output is correct
31 Correct 1879 ms 22136 KB Output is correct
32 Correct 1765 ms 22208 KB Output is correct
33 Correct 1617 ms 21148 KB Output is correct
34 Correct 1636 ms 21116 KB Output is correct
35 Correct 1710 ms 21652 KB Output is correct
36 Correct 1503 ms 20252 KB Output is correct
37 Correct 1746 ms 22120 KB Output is correct
38 Correct 1534 ms 20196 KB Output is correct
39 Correct 1633 ms 21392 KB Output is correct
40 Correct 1674 ms 21356 KB Output is correct
41 Incorrect 157 ms 15420 KB Output isn't correct
42 Halted 0 ms 0 KB -