Submission #888187

#TimeUsernameProblemLanguageResultExecution timeMemory
888187UnforgettableplSnake Escaping (JOI18_snake_escaping)C++17
12 / 100
578 ms13716 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = INT64_MAX; int arr[1024]; int ask(string &a,int perm){ int idx = 0; for(int x=0;x<a.size();x++){ if(a[x]=='1')idx|=(1<<x); else if(a[x]=='?'){idx|=((perm&1)<<x);perm>>=1;} } return arr[idx]; } int32_t main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int L,q; cin >> L >> q; for(int i=0;i<(1<<L);i++){ char a;cin>>a;a-='0'; arr[i]=a; } map<string,int> memo; for (int i = 0; i < q; i++) { string a;cin>>a; reverse(a.begin(), a.end()); if(memo.count(a)){cout<<memo[a]<<'\n';continue;} int n = count(a.begin(), a.end(),'?'); int ans = 0; for(int perm = 0;perm<(1<<n);perm++){ ans+=ask(a,perm); } cout << ans << '\n'; memo[a]=ans; } }

Compilation message (stderr)

snake_escaping.cpp: In function 'long long int ask(std::string&, long long int)':
snake_escaping.cpp:11:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int x=0;x<a.size();x++){
      |                 ~^~~~~~~~~
#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...