제출 #568560

#제출 시각아이디문제언어결과실행 시간메모리
568560FEDIKUSSnake Escaping (JOI18_snake_escaping)C++17
22 / 100
632 ms50124 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define xx first #define yy second #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++) #define fb(i,s,f) for(ll (i)=s-1;(i)>=f;(i)--) #define ffi(i,s,f) for(ll (i)=s;(i)<=(f);(i)++) #define fbi(i,s,f) for(ll (i)=s;(i)>=(f);(i)--) #define srt(a) sort(a.begin(),a.end()); #define srtg(a,ll) sort(a.begin(),a.end(),greater<ll>()) #define lb(a,x) lower_bound(a.begin(),a.end(),x) #define ub(a,x) upper_bound(a.begin(),a.end(),x) #define fnd(a,x) find(a.begin(),a.end(),x) #define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) using namespace std; typedef long long ll; typedef pair<ll,ll> pii; typedef pair<ll,ll> pll; typedef string str; const ll logg=21; ll sub[1<<logg],sup[1<<logg]; ll com(ll a){ return a^((1<<logg)-1); } void solve(){ ll l,q; cin>>l>>q; str s; cin>>s; ff(mask,0,(1<<l)) sub[mask]=s[mask]-'0'; ff(i,0,logg) ff(mask,0,(1<<logg)) if((1<<i)&mask) sub[mask]+=sub[mask^(1<<i)]; ff(mask,0,(1<<l)) sup[mask]=s[mask]-'0'; ff(i,0,logg) ff(mask,0,(1<<logg)) if((1<<i)&com(mask)) sup[mask]+=sup[mask^(1<<i)]; while(q--){ str t; cin>>t; ll one=0,zero=0; for(char i:t) if(i=='0') zero++; else if(i=='1') one++; ll res=0; if(one<=6){ ll mask=0; ll nfixed=0; ff(i,0,t.size()){ if(t[i]=='1') mask+=(1<<(l-i-1)); if(t[i]=='?') nfixed+=(1<<(l-i-1)); } for(ll submask=mask;;submask=(submask-1)&mask){ if((one-__builtin_popcount(submask|nfixed))&1) res-=sub[submask|nfixed]; else res+=sub[submask|nfixed]; if(submask==0) break; } }else if(zero<=6){ ll mask=0; ll ones=0; ff(i,0,t.size()){ if(t[i]=='0') mask+=(1<<(l-i-1)); if(t[i]=='1') ones+=(1<<(l-i-1)); } for(ll submask=mask;;submask=(submask-1)&mask){ if(__builtin_popcount(submask)&1) res-=sup[submask|ones]; else res+=sup[submask|ones]; if(submask==0) break; } }else{ ll mask=0; ff(i,0,t.size()){ if(t[i]=='?') mask+=(1<<(l-i-1)); } for(ll submask=mask;;submask=(submask-1)&mask){ res+=s[submask]-'0'; if(submask==0) break; } } cout<<abs(res)<<"\n"; } } int main(){ ios; ll t=1; //cin>>t; while(t--) solve(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

snake_escaping.cpp: In function 'void solve()':
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'mask' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:40:5: note: in expansion of macro 'ff'
   40 |     ff(mask,0,(1<<l)) sub[mask]=s[mask]-'0';
      |     ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:41:5: note: in expansion of macro 'ff'
   41 |     ff(i,0,logg) ff(mask,0,(1<<logg)) if((1<<i)&mask) sub[mask]+=sub[mask^(1<<i)];
      |     ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'mask' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:41:18: note: in expansion of macro 'ff'
   41 |     ff(i,0,logg) ff(mask,0,(1<<logg)) if((1<<i)&mask) sub[mask]+=sub[mask^(1<<i)];
      |                  ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'mask' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:42:5: note: in expansion of macro 'ff'
   42 |     ff(mask,0,(1<<l)) sup[mask]=s[mask]-'0';
      |     ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:43:5: note: in expansion of macro 'ff'
   43 |     ff(i,0,logg) ff(mask,0,(1<<logg)) if((1<<i)&com(mask)) sup[mask]+=sup[mask^(1<<i)];
      |     ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'mask' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:43:18: note: in expansion of macro 'ff'
   43 |     ff(i,0,logg) ff(mask,0,(1<<logg)) if((1<<i)&com(mask)) sup[mask]+=sup[mask^(1<<i)];
      |                  ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:53:13: note: in expansion of macro 'ff'
   53 |             ff(i,0,t.size()){
      |             ^~
snake_escaping.cpp:9:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                                ~~~^~~~
snake_escaping.cpp:53:13: note: in expansion of macro 'ff'
   53 |             ff(i,0,t.size()){
      |             ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:65:13: note: in expansion of macro 'ff'
   65 |             ff(i,0,t.size()){
      |             ^~
snake_escaping.cpp:9:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                                ~~~^~~~
snake_escaping.cpp:65:13: note: in expansion of macro 'ff'
   65 |             ff(i,0,t.size()){
      |             ^~
snake_escaping.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                          ^
snake_escaping.cpp:76:13: note: in expansion of macro 'ff'
   76 |             ff(i,0,t.size()){
      |             ^~
snake_escaping.cpp:9:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define ff(i,s,f) for(ll (i)=s;(i)<(f);(i)++)
      |                                ~~~^~~~
snake_escaping.cpp:76:13: note: in expansion of macro 'ff'
   76 |             ff(i,0,t.size()){
      |             ^~
#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...