Submission #255689

# Submission time Handle Problem Language Result Execution time Memory
255689 2020-08-01T14:37:16 Z egekabas Snake Escaping (JOI18_snake_escaping) C++14
12 / 100
1618 ms 65540 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<ll, ll>  pii;
typedef pair<ld, ld>  pld;
ll l, q;
string s;
ll a = 8, b = 5;
ll sum[(1<<13)+10][(1<<8)+10];
ll p3[30];
unordered_map<ll, ll> dp[(1<<13)+10];
ll v2;
ll n;
ll calc(ll step, ll idx, ll val){
    if(dp[idx][val] != 0){ 
        return dp[idx][val]-1;
    }
    if(idx >= (1<<a)){
        //cout << s << '\n' << idx << '\n';
        dp[idx][val] = sum[idx-(1<<a)][v2]+1;
        return dp[idx][val]-1;
    }
    dp[idx][val] = 1;
    ll curval = (val%(p3[step+1]))/p3[step];
    //cout << step << ' ' << curval << '\n';
    if(curval != 1)
        dp[idx][val] += calc(step-1, idx*2, val-curval*p3[step]);
    if(curval != 0)
        dp[idx][val] += calc(step-1, idx*2+1, val-curval*p3[step]);
    
    return dp[idx][val]-1;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    p3[0] = 1;
    for(ll i = 1; i < 30; ++i)
        p3[i] = 3*p3[i-1];
    cin >> l >> q;
    a = min(a, l);

    n = (1<<l);
    cin >> s;
    ll cur = (1<<a);
    for(ll i = 0; i < n; ++i){
        ll v1 = cur;
        ++cur;
        if(cur == (1<<(a+1)))
            cur = (1<<a);
        for(ll bit = 0; bit < (1<<b); ++bit){
            ll idx = 0;
            ll val = (i>>a);
            for(ll j = 0; j < b; ++j){
                if((1<<j)&bit)
                    idx += p3[j]*(val%2);
                else
                    idx += p3[j]*2;
                val /= 2;
            }
            sum[v1-(1<<a)][idx] += s[i]-'0';
        }
    }
    for(ll i = 0; i < q; ++i){
        cin >> s;
        reverse(s.begin(), s.end());
        ll v1 = 0;
        for(ll i = 0; i < s.size(); ++i){
            if(s[i] == '1')
                v1 += p3[i];
            else if(s[i] == '?')
                v1 += 2*p3[i];
        }
        v2 = 0;
        for(ll i = a; i < a+b; ++i){
            if(i >= s.size())
                v2 += 2*p3[i-a];
            else if(s[i] == '1')
                v2 += p3[i-a];
            else if(s[i] == '?')
                v2 += 2*p3[i-a];
        }
        cout << calc(a-1, 1, v1) << '\n';
    }
} 

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:77:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(ll i = 0; i < s.size(); ++i){
                       ~~^~~~~~~~~~
snake_escaping.cpp:85:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(i >= s.size())
                ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1536 KB Output is correct
2 Correct 3 ms 1664 KB Output is correct
3 Correct 4 ms 1920 KB Output is correct
4 Correct 4 ms 1920 KB Output is correct
5 Correct 8 ms 2432 KB Output is correct
6 Correct 7 ms 2176 KB Output is correct
7 Correct 6 ms 2304 KB Output is correct
8 Correct 3 ms 1408 KB Output is correct
9 Correct 3 ms 1408 KB Output is correct
10 Correct 5 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1536 KB Output is correct
2 Correct 3 ms 1664 KB Output is correct
3 Correct 4 ms 1920 KB Output is correct
4 Correct 4 ms 1920 KB Output is correct
5 Correct 8 ms 2432 KB Output is correct
6 Correct 7 ms 2176 KB Output is correct
7 Correct 6 ms 2304 KB Output is correct
8 Correct 3 ms 1408 KB Output is correct
9 Correct 3 ms 1408 KB Output is correct
10 Correct 5 ms 1664 KB Output is correct
11 Correct 261 ms 5624 KB Output is correct
12 Correct 276 ms 5368 KB Output is correct
13 Correct 300 ms 6264 KB Output is correct
14 Correct 303 ms 6008 KB Output is correct
15 Correct 300 ms 7544 KB Output is correct
16 Correct 362 ms 8056 KB Output is correct
17 Correct 503 ms 12296 KB Output is correct
18 Correct 206 ms 6392 KB Output is correct
19 Correct 248 ms 3448 KB Output is correct
20 Correct 271 ms 5368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1536 KB Output is correct
2 Correct 3 ms 1664 KB Output is correct
3 Correct 4 ms 1920 KB Output is correct
4 Correct 4 ms 1920 KB Output is correct
5 Correct 8 ms 2432 KB Output is correct
6 Correct 7 ms 2176 KB Output is correct
7 Correct 6 ms 2304 KB Output is correct
8 Correct 3 ms 1408 KB Output is correct
9 Correct 3 ms 1408 KB Output is correct
10 Correct 5 ms 1664 KB Output is correct
11 Correct 261 ms 5624 KB Output is correct
12 Correct 276 ms 5368 KB Output is correct
13 Correct 300 ms 6264 KB Output is correct
14 Correct 303 ms 6008 KB Output is correct
15 Correct 300 ms 7544 KB Output is correct
16 Correct 362 ms 8056 KB Output is correct
17 Correct 503 ms 12296 KB Output is correct
18 Correct 206 ms 6392 KB Output is correct
19 Correct 248 ms 3448 KB Output is correct
20 Correct 271 ms 5368 KB Output is correct
21 Correct 322 ms 7160 KB Output is correct
22 Correct 352 ms 10360 KB Output is correct
23 Correct 1618 ms 53496 KB Output is correct
24 Correct 1330 ms 41604 KB Output is correct
25 Correct 938 ms 40964 KB Output is correct
26 Runtime error 1186 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1536 KB Output is correct
2 Correct 3 ms 1664 KB Output is correct
3 Correct 4 ms 1920 KB Output is correct
4 Correct 4 ms 1920 KB Output is correct
5 Correct 8 ms 2432 KB Output is correct
6 Correct 7 ms 2176 KB Output is correct
7 Correct 6 ms 2304 KB Output is correct
8 Correct 3 ms 1408 KB Output is correct
9 Correct 3 ms 1408 KB Output is correct
10 Correct 5 ms 1664 KB Output is correct
11 Runtime error 1221 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1536 KB Output is correct
2 Correct 3 ms 1664 KB Output is correct
3 Correct 4 ms 1920 KB Output is correct
4 Correct 4 ms 1920 KB Output is correct
5 Correct 8 ms 2432 KB Output is correct
6 Correct 7 ms 2176 KB Output is correct
7 Correct 6 ms 2304 KB Output is correct
8 Correct 3 ms 1408 KB Output is correct
9 Correct 3 ms 1408 KB Output is correct
10 Correct 5 ms 1664 KB Output is correct
11 Correct 261 ms 5624 KB Output is correct
12 Correct 276 ms 5368 KB Output is correct
13 Correct 300 ms 6264 KB Output is correct
14 Correct 303 ms 6008 KB Output is correct
15 Correct 300 ms 7544 KB Output is correct
16 Correct 362 ms 8056 KB Output is correct
17 Correct 503 ms 12296 KB Output is correct
18 Correct 206 ms 6392 KB Output is correct
19 Correct 248 ms 3448 KB Output is correct
20 Correct 271 ms 5368 KB Output is correct
21 Correct 322 ms 7160 KB Output is correct
22 Correct 352 ms 10360 KB Output is correct
23 Correct 1618 ms 53496 KB Output is correct
24 Correct 1330 ms 41604 KB Output is correct
25 Correct 938 ms 40964 KB Output is correct
26 Runtime error 1186 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Halted 0 ms 0 KB -