Submission #287569

# Submission time Handle Problem Language Result Execution time Memory
287569 2020-08-31T20:11:19 Z Leonardo_Paes Snake Escaping (JOI18_snake_escaping) C++17
0 / 100
875 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
const int maxn = 13;
typedef pair<int,int> pii;
map<pii, int> dp;
int nxt[(1<<maxn) + 10];
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int l, q;
    cin >> l >> q;
    vector<int> v((1<<l));
    for(int i=0; i<(1<<l); i++){
        char a;
        cin >> a;
        v[i] = a - '0';
    }
    for(int i=1; i<(1<<l); i++) nxt[i] = (i&-i); // rightmost set bit tipo na BIT -> ok
    for(int a=(1<<l)-1; a>=0; a--){
        dp[{a, 0}] = v[a]; // caso base -> ok
        for(int b=1; b<(1<<l); b++){
            int x = nxt[b];
            if(a|x < (1<<l)) dp[{a, b}] = dp[{a|x, b^x}]; // será?
            dp[{a, b}] += dp[{a, b^x}]; // unicos dois casos -> ok
        }
    }
    while(q--){
        string s;
        cin >> s;
        int a = 0, b = 0;
        for(int i=0; i<l; i++){
            if(s[i] == '1') a += (1<<(l-i-1));
            if(s[i] == '?') b += (1<<(l-i-1));
        }
        cout << dp[{a, b}] << "\n";
    }
    return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:24:20: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   24 |             if(a|x < (1<<l)) dp[{a, b}] = dp[{a|x, b^x}]; // será?
      |                  ~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 875 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 875 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 875 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 875 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 875 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -