Submission #934119

#TimeUsernameProblemLanguageResultExecution timeMemory
934119Rafi22Snake Escaping (JOI18_snake_escaping)C++14
22 / 100
1879 ms24100 KiB
#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 (stderr)

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;
      |          ^~~~~~~~~~~~~~~~~~~
#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...