Submission #1056518

# Submission time Handle Problem Language Result Execution time Memory
1056518 2024-08-13T09:52:03 Z lozergam Snake Escaping (JOI18_snake_escaping) C++17
0 / 100
1 ms 348 KB
#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

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:7:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define For(i, n) for(int (i) = 0 ; (i) < (n) ; (i)++)
      |                           ^
snake_escaping.cpp:22:5: note: in expansion of macro 'For'
   22 |     For(i, 1ll << n)
      |     ^~~
snake_escaping.cpp:7:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define For(i, n) for(int (i) = 0 ; (i) < (n) ; (i)++)
      |                           ^
snake_escaping.cpp:32:5: note: in expansion of macro 'For'
   32 |     For(i, n)
      |     ^~~
snake_escaping.cpp:7:27: warning: unnecessary parentheses in declaration of 'mask' [-Wparentheses]
    7 | #define For(i, n) for(int (i) = 0 ; (i) < (n) ; (i)++)
      |                           ^
snake_escaping.cpp:33:9: note: in expansion of macro 'For'
   33 |         For(mask, 1ll << i)
      |         ^~~
snake_escaping.cpp:7:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define For(i, n) for(int (i) = 0 ; (i) < (n) ; (i)++)
      |                           ^
snake_escaping.cpp:45:9: note: in expansion of macro 'For'
   45 |         For(i, 3)mask[i] = 0, cnt[i] = 0;
      |         ^~~
snake_escaping.cpp:7:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define For(i, n) for(int (i) = 0 ; (i) < (n) ; (i)++)
      |                           ^
snake_escaping.cpp:51:9: note: in expansion of macro 'For'
   51 |         For(i, sz(s))
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -