Submission #115990

# Submission time Handle Problem Language Result Execution time Memory
115990 2019-06-10T06:43:41 Z oolimry Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
770 ms 27768 KB
#include <bits/stdc++.h>

using namespace std;


int value[2000000];
int memo[2000005];
int n , q;
int tostring(string s){
    int v = 0;
    for(int i = 0;i < n;i++){
        v *= 3;
        if(s[i] == '0') v++;
        else if(s[i] == '1') v += 2;
    }
    return v;
}
int dp(string s){
    int x = tostring(s);
    if(memo[x] != -1) return memo[x];
    for(int i = 0;i < n;i++){
        if(s[i] == '?'){
            string s0 = s;
            string s1 = s;
            s0[i] = '0';
            s1[i] = '1';
            int ans = dp(s0) + dp(s1);
            //cout << s << " " << ans << "\n";
            memo[x] = ans;
            return ans;
        }
    }
    int v = 0;
    for(int i = 0;i < n;i++){
        v *= 2;
        if(s[i] == '1') v++;
    }
    //cout << s << " " << value[v] << "\n";
    memo[x] = value[v];
    return value[v];
}
int main()
{
    //freopen("i.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    fill(memo,memo+2000000,-1);

    cin >> n >> q;
    string s;
    cin >> s;
    for(int i = 0;i < s.length();i++){
        value[i] = s[i] - '0';
    }

    for(int qq = 0;qq < q;qq++){
        cin >> s;

        cout << dp(s) << "\n";
    }


    return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:52: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 Correct 9 ms 8192 KB Output is correct
2 Correct 9 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 9 ms 8236 KB Output is correct
5 Correct 13 ms 8192 KB Output is correct
6 Correct 9 ms 8192 KB Output is correct
7 Correct 10 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 8 ms 8224 KB Output is correct
10 Correct 9 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8192 KB Output is correct
2 Correct 9 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 9 ms 8236 KB Output is correct
5 Correct 13 ms 8192 KB Output is correct
6 Correct 9 ms 8192 KB Output is correct
7 Correct 10 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 8 ms 8224 KB Output is correct
10 Correct 9 ms 8192 KB Output is correct
11 Correct 167 ms 13304 KB Output is correct
12 Correct 215 ms 12380 KB Output is correct
13 Correct 206 ms 11768 KB Output is correct
14 Correct 214 ms 11976 KB Output is correct
15 Correct 208 ms 12704 KB Output is correct
16 Correct 218 ms 11864 KB Output is correct
17 Correct 232 ms 11896 KB Output is correct
18 Correct 181 ms 13816 KB Output is correct
19 Correct 204 ms 10832 KB Output is correct
20 Correct 172 ms 12408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8192 KB Output is correct
2 Correct 9 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 9 ms 8236 KB Output is correct
5 Correct 13 ms 8192 KB Output is correct
6 Correct 9 ms 8192 KB Output is correct
7 Correct 10 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 8 ms 8224 KB Output is correct
10 Correct 9 ms 8192 KB Output is correct
11 Correct 167 ms 13304 KB Output is correct
12 Correct 215 ms 12380 KB Output is correct
13 Correct 206 ms 11768 KB Output is correct
14 Correct 214 ms 11976 KB Output is correct
15 Correct 208 ms 12704 KB Output is correct
16 Correct 218 ms 11864 KB Output is correct
17 Correct 232 ms 11896 KB Output is correct
18 Correct 181 ms 13816 KB Output is correct
19 Correct 204 ms 10832 KB Output is correct
20 Correct 172 ms 12408 KB Output is correct
21 Correct 182 ms 12792 KB Output is correct
22 Correct 272 ms 13024 KB Output is correct
23 Correct 432 ms 11896 KB Output is correct
24 Correct 412 ms 11872 KB Output is correct
25 Correct 396 ms 13432 KB Output is correct
26 Correct 568 ms 13716 KB Output is correct
27 Correct 740 ms 25516 KB Output is correct
28 Correct 185 ms 27768 KB Output is correct
29 Correct 223 ms 23928 KB Output is correct
30 Correct 203 ms 26180 KB Output is correct
31 Correct 586 ms 26000 KB Output is correct
32 Correct 427 ms 25920 KB Output is correct
33 Correct 295 ms 24824 KB Output is correct
34 Correct 555 ms 25028 KB Output is correct
35 Correct 770 ms 25452 KB Output is correct
36 Correct 172 ms 23932 KB Output is correct
37 Correct 249 ms 26000 KB Output is correct
38 Correct 240 ms 24016 KB Output is correct
39 Correct 419 ms 25204 KB Output is correct
40 Correct 397 ms 24956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8192 KB Output is correct
2 Correct 9 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 9 ms 8236 KB Output is correct
5 Correct 13 ms 8192 KB Output is correct
6 Correct 9 ms 8192 KB Output is correct
7 Correct 10 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 8 ms 8224 KB Output is correct
10 Correct 9 ms 8192 KB Output is correct
11 Runtime error 30 ms 27160 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8192 KB Output is correct
2 Correct 9 ms 8192 KB Output is correct
3 Correct 10 ms 8192 KB Output is correct
4 Correct 9 ms 8236 KB Output is correct
5 Correct 13 ms 8192 KB Output is correct
6 Correct 9 ms 8192 KB Output is correct
7 Correct 10 ms 8192 KB Output is correct
8 Correct 9 ms 8192 KB Output is correct
9 Correct 8 ms 8224 KB Output is correct
10 Correct 9 ms 8192 KB Output is correct
11 Correct 167 ms 13304 KB Output is correct
12 Correct 215 ms 12380 KB Output is correct
13 Correct 206 ms 11768 KB Output is correct
14 Correct 214 ms 11976 KB Output is correct
15 Correct 208 ms 12704 KB Output is correct
16 Correct 218 ms 11864 KB Output is correct
17 Correct 232 ms 11896 KB Output is correct
18 Correct 181 ms 13816 KB Output is correct
19 Correct 204 ms 10832 KB Output is correct
20 Correct 172 ms 12408 KB Output is correct
21 Correct 182 ms 12792 KB Output is correct
22 Correct 272 ms 13024 KB Output is correct
23 Correct 432 ms 11896 KB Output is correct
24 Correct 412 ms 11872 KB Output is correct
25 Correct 396 ms 13432 KB Output is correct
26 Correct 568 ms 13716 KB Output is correct
27 Correct 740 ms 25516 KB Output is correct
28 Correct 185 ms 27768 KB Output is correct
29 Correct 223 ms 23928 KB Output is correct
30 Correct 203 ms 26180 KB Output is correct
31 Correct 586 ms 26000 KB Output is correct
32 Correct 427 ms 25920 KB Output is correct
33 Correct 295 ms 24824 KB Output is correct
34 Correct 555 ms 25028 KB Output is correct
35 Correct 770 ms 25452 KB Output is correct
36 Correct 172 ms 23932 KB Output is correct
37 Correct 249 ms 26000 KB Output is correct
38 Correct 240 ms 24016 KB Output is correct
39 Correct 419 ms 25204 KB Output is correct
40 Correct 397 ms 24956 KB Output is correct
41 Runtime error 30 ms 27160 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Halted 0 ms 0 KB -