Submission #1048168

#TimeUsernameProblemLanguageResultExecution timeMemory
1048168khanhtbSnake Escaping (JOI18_snake_escaping)C++14
22 / 100
219 ms24148 KiB
#pragma GCC optimize("O3,unroll-loops") #include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define ld long double #define pb push_back #define pf push_front #define vi vector<ll> #define vii vector<vi> #define pll pair<ll, ll> #define vpll vector<pll> #define all(a) a.begin(), a.end() #define fi first #define se second using namespace std; const int mod = 998244353; const ll inf = 2e18; const int B = 320; const int N = 2e6+8; int n,q,a[N]; int sub[N],sup[N]; void solve(){ cin >> n >> q; for(int i = 0; i < 1<<n; i++){ char c;cin >> c; a[i] = c-'0'; sub[i] = sup[i] = a[i]; } for(int i = 0; i < n; i++){ for(int mask = 0; mask < 1<<n; mask++){ if(mask>>i&1) sub[mask] += sub[mask^(1<<i)]; else sup[mask] += sup[mask^(1<<i)]; } } while(q--){ string t;cin >> t; int mask[3] = {0}; int cnt[3] = {0}; reverse(all(t)); for(int i = 0; i < t.size(); i++){ int type; if(t[i] == '0') type = 0; else if(t[i] == '1') type = 1; else type = 2; cnt[type]++; mask[type] |= (1<<i); } int ans = 0; if(cnt[2] <= 7){ ll ans = 0; for(int m = mask[2]; ; m = (m-1)&mask[2]){ ans += a[mask[1]|m]; if(m == 0) break; } cout << ans << '\n'; } else if(cnt[1] <= 7){ ll ans = 0; for(int m = mask[1]; ; m = (m-1)&mask[1]){ if(__builtin_popcount(m)&1) ans -= sub[(m ^ mask[1]) | mask[2]]; else ans += sub[(m ^ mask[1]) | mask[2]]; if(m == 0) break; } cout << ans << '\n'; } else{ ll ans = 0; for(int m = mask[1]; ; m = (m-1)&mask[0]){ if(__builtin_popcount(m)&1) ans -= sup[(m ^ mask[0]) | mask[2]]; else ans += sup[(m ^ mask[0]) | mask[2]]; if(m == 0) break; } cout << ans << '\n'; } } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("test.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll T = 1; // cin >> T; for (ll i = 1; i <= T; i++) { solve(); cout << '\n'; } }

Compilation message (stderr)

snake_escaping.cpp: In function 'void solve()':
snake_escaping.cpp:40:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int i = 0; i < t.size(); i++){
      |                        ~~^~~~~~~~~~
snake_escaping.cpp:48:13: warning: unused variable 'ans' [-Wunused-variable]
   48 |         int ans = 0;
      |             ^~~
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...