Submission #792470

#TimeUsernameProblemLanguageResultExecution timeMemory
792470CookieSnake Escaping (JOI18_snake_escaping)C++14
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> #include<fstream> #pragma GCC optimize("Ofast,O3,unroll-loops") #pragma GCC target("avx2") using namespace std; //ifstream fin("FEEDING.INP"); //ofstream fout("FEEDING.OUT"); #define sz(a) (int)a.size() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> const ll mxn = 3e5 + 5, base = 972663749; const ll mod = 911382323, mxv = 1e9 + 1, inf = 2e9; int l, q; int big[(1 << 20)], small[(1 << 20)]; string s; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); scanf("%d %d", &l, &q); cin >> s; for(int i = 0; i < (1 << l); i++){ scanf(" %c", &s[i]); big[i] = (s[i] - '0'); small[i] = (s[i] - '0'); } for(int i = 0; i < l; i++){ for(int j = 0; j < (1 << l); j++){ if(j & (1 << i))small[j] += small[j ^ (1 << i)]; else big[j] += big[j ^ (1 << i)]; } } while(q--){ char c; int zero = 0, one = 0, que = 0; for(int i = 0; i < l; i++){ scanf(" %c", &c); if(c == '0')zero += (1 << (l - i - 1)); else if(c == '1')one += (1 << (l - i - 1)); else que += (1 << (l - i - 1)); } int ans = 0; if(__builtin_popcount(que) <= 6){ int mask = one; for(int j = que;j; j = (j - 1) & que){ //cout << (mask | j) << " "; ans += (s[mask | j] - '0'); } ans += (s[mask] - '0'); }else if(__builtin_popcount(one) <= 6){ int mask = que; for(int j = one;j; j = (j - 1) & one){ if((__builtin_popcount(one) - __builtin_popcount(j)) & 1)ans -= small[mask | j]; else ans += small[mask | j]; } if((__builtin_popcount(one)) & 1)ans -= small[mask]; else ans += small[mask]; }else{ int mask = one; for(int j = zero;j; j = (j - 1) & zero){ if(__builtin_popcount(j) & 1)ans -= big[mask | j]; else ans += big[mask | j]; } ans += big[mask]; } cout << ans << "\n"; } return(0); }

Compilation message (stderr)

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d %d", &l, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
snake_escaping.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf(" %c", &s[i]);
      |         ~~~~~^~~~~~~~~~~~~~
snake_escaping.cpp:47:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |             scanf(" %c", &c);
      |             ~~~~~^~~~~~~~~~~
#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...