Submission #116028

# Submission time Handle Problem Language Result Execution time Memory
116028 2019-06-10T08:48:35 Z oolimry Snake Escaping (JOI18_snake_escaping) C++14
0 / 100
63 ms 65536 KB
#include <bits/stdc++.h>

using namespace std;


int value[2000000];
int memo[6600][4100];
int n , q;
int tleft;
int tostring(string s){
    int v = 0;
    for(int i = 0;i < n - tleft;i++){
        v *= 3;
        if(s[i] == '0') v++;
        else if(s[i] == '1') v += 2;
    }
    return v;
}



int dp(string s, int t){
    int x = tostring(s);
    if(memo[x][t] != -1) return memo[x][t];
    for(int i = 0;i < n - tleft;i++){
        if(s[i] == '?'){
            string s0 = s;
            string s1 = s;
            s0[i] = '0';
            s1[i] = '1';
            int ans = dp(s0,t) + dp(s1,t);
            //cout << s << " " << ans << "\n";
            memo[x][t] = ans;
            return ans;
        }
    }
    int v = 0;
    for(int i = 0;i < n - tleft;i++){
        v *= 2;
        if(s[i] == '1') v++;
    }
    v <<= tleft;
    v += t;
    //cout << s << " " << t << " " << v << "ffff\n";
    memo[x][t] = value[v];
    return value[v];
}

vector<int> options;
void genop(string s){
    for(int i = 0;i < tleft;i++){
        if(s[i] == '?'){
            string s0 = s;
            string s1 = s;
            s0[i] = '0';
            s1[i] = '1';
            genop(s1);
            genop(s0);
            return;
        }
    }
    int v = 0;
    for(int i = 0;i < tleft;i++){
        v <<= 1;
        if(s[i] == '1')v++;
    }
    options.push_back(v);
}
int main()
{
    //freopen("i.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    for(int i = 0;i < 6600;i++){
        for(int j = 0;j < 4100;j++){
            memo[i][j] = -1;
        }
    }

    cin >> n >> q;
    string s;
    cin >> s;
    for(int i = 0;i < s.length();i++){
        value[i] = s[i] - '0';
    }
    int split = 8;
    tleft = max(0, n - split);
    for(int qq = 0;qq < q;qq++){
        cin >> s;
        string s1 = "";
        for(int i = 0;i < split;i++){
            s1 += s[i];
        }
        string s2 = "";
        for(int i = split;i < n;i++){
            s2 += s[i];
        }

        //cout << s1 << " " << s2 << "\n";

        int ans = 0;
        options.clear();
        genop(s2);
        for(int ss : options){
            //cout << ss << "\n";
            ans += dp(s1,ss);
        }
        cout << ans << "\n";
        //cout << dp(s) << "\n";
    }




    return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:83:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i < s.length();i++){
                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -