Submission #96089

#TimeUsernameProblemLanguageResultExecution timeMemory
96089MvCSnake Escaping (JOI18_snake_escaping)C++11
0 / 100
2 ms376 KiB
#include "bits/stdc++.h" using namespace std; #define fi first #define se second #define ll long long #define dbg(v) cerr<<#v<<" = "<<v<<'\n' #define vi vector<int> #define vl vector <ll> #define pii pair<int,int> #define mp make_pair #define db long double #define pb push_back #define all(s) s.begin(),s.end() template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;} template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;} int D0[1 << 20]; int D1[1 << 20]; char str[1 << 20]; int coef[1 << 20]; char s[64]; int main(void) { int n,q; scanf("%d%d%s",&n,&q,str); const int N = 1 << n; for (int i = 0;i < N;++i) str[i] -= '0'; for (int i = 0;i < N;++i) coef[i] = __builtin_popcount(i) & 1 ? -1 : 1; for (int i = 0;i < N;++i) D0[i] = D1[i] = str[i]; for (int i = 0;i < n;++i) for (int mask = 0;mask < N;++mask) if ((mask >> i) & 1) D0[mask ^ (1 << i)] += D0[mask]; else D1[mask ^ (1 << i)] += D1[mask]; while (q --) { scanf("%s",s); reverse(s,s + n); int a = 0,b = 0,c = 0; int la = 0,lb = 0,lc = 0; for (int i = 0;i < n;++i) { if (s[i] == '0') a |= 1 << i,++la; else if (s[i] == '1') b |= 1 << i,++lb; else c |= 1 << i,++lc; } int ans = 0; if (la <= lb && la <= lc) { for (int mask = a;mask >= 0;mask = !mask ? -1 : ((mask - 1) & a)) ans += coef[mask] * D0[(N - 1) ^ mask | c]; } else if (lb <= la && lb <= lc) { for (int mask = b;mask >= 0;mask = !mask ? -1 : ((mask - 1) & b)) ans += coef[mask] * D1[mask | c]; } else { for (int mask = c;mask >= 0;mask = !mask ? -1 : ((mask - 1) & c)) ans += str[mask | b]; } ans = abs(ans); printf("%d\n",ans); } return 0; }

Compilation message (stderr)

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:32:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i = 0;i < n;++i)
     ^~~
snake_escaping.cpp:38:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     while (q --) {
     ^~~~~
snake_escaping.cpp:55:39: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
        ans += coef[mask] * D0[(N - 1) ^ mask | c];
                               ~~~~~~~~^~~~~~
snake_escaping.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%s",&n,&q,str);
     ~~~~~^~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:39:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
      scanf("%s",s);
      ~~~~~^~~~~~~~
#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...