답안 #255703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255703 2020-08-01T15:42:17 Z egekabas Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
337 ms 58608 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;
int l, q;
string s;
const int n7 = 2187;
const int n13 = 1594323;
int val[1000009][2];
int av[n7][(1<<7)];
int child[n13][2];
int ans[1000009];
int tr[n13];
int dp[n13];
int a, b;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    cin >> l >> q;
    cin >> s;
    a = min(l, 0);
    b = l-a;
    for(int i = 0; i < q; ++i){
        string t;
        cin >> t;
        for(int j = 0; j < a; ++j){
            val[i][0] *= 3;
            if(t[j] != '?')
                val[i][0] += t[j]-'0';
            else
                val[i][0] += 2;
        }
        for(int j = a; j < l; ++j){
            val[i][1] *= 3;
            if(t[j] != '?')
                val[i][1] += t[j]-'0';
            else
                val[i][1] += 2;
        }
    }
    for(int i = 0; i < n7; ++i)
        for(int j = 0; j < (1<<7); ++j){
            av[i][j] = 1;
            int v1 = i, v2 = j;
            for(int k = 0; k < 7; ++k){
                if(v1%3 != 2 && v1%3 != v2%2)
                    av[i][j] = 0;
                v1 /= 3;
                v2 /= 2;
            }
        }
    for(int i = 0; i < n13; ++i){
        child[i][0] = child[i][1] = -1;
        int cur = 1;
        int val = i;
        for(int j = 0; j < 13; ++j){
            if(val%3 == 2){
                child[i][0] = i-cur;
                child[i][1] = i-2*cur;
                break;
            }
            cur *= 3;
            val /= 3;
        }
    }
    for(int i = 0; i < n13; ++i){
        int val = i;
        for(int j = 0; j < 13; ++j){
            tr[i] += (1<<j)*(val%3 > 0);
            val /= 3;
        }
    }
    for(int i = 0; i < (1<<a); ++i){
        for(int j = 0; j < n13; ++j){
            if(child[j][0] == -1){
                dp[j] = 0;
                if(tr[j] + (1<<b)*i < s.size())
                    dp[j] = s[tr[j]+(1<<b)*i]-'0';
            }
            else
                dp[j] = dp[child[j][0]]+dp[child[j][1]];
        }
        for(int j = 0; j < q; ++j){
            if(av[val[j][0]][i] == 0) continue;
            //cout << j << ' ' << i << '\n';
            ans[j] += dp[val[j][1]];
        }
    }
    for(int i = 0; i < q; ++i){
        //cout << tr[val[i][0]] << ' ';
        cout << ans[i] << '\n';
    
    }
} 

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:90:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(tr[j] + (1<<b)*i < s.size())
                    ~~~~~~~~~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 26360 KB Output is correct
2 Correct 74 ms 26488 KB Output is correct
3 Correct 73 ms 26488 KB Output is correct
4 Correct 71 ms 26360 KB Output is correct
5 Correct 72 ms 26484 KB Output is correct
6 Correct 72 ms 26488 KB Output is correct
7 Correct 78 ms 26488 KB Output is correct
8 Correct 73 ms 26420 KB Output is correct
9 Correct 71 ms 26360 KB Output is correct
10 Correct 74 ms 26360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 26360 KB Output is correct
2 Correct 74 ms 26488 KB Output is correct
3 Correct 73 ms 26488 KB Output is correct
4 Correct 71 ms 26360 KB Output is correct
5 Correct 72 ms 26484 KB Output is correct
6 Correct 72 ms 26488 KB Output is correct
7 Correct 78 ms 26488 KB Output is correct
8 Correct 73 ms 26420 KB Output is correct
9 Correct 71 ms 26360 KB Output is correct
10 Correct 74 ms 26360 KB Output is correct
11 Correct 286 ms 44280 KB Output is correct
12 Correct 320 ms 43896 KB Output is correct
13 Correct 283 ms 43260 KB Output is correct
14 Correct 279 ms 43256 KB Output is correct
15 Correct 294 ms 44280 KB Output is correct
16 Correct 300 ms 43384 KB Output is correct
17 Correct 288 ms 43384 KB Output is correct
18 Correct 267 ms 45304 KB Output is correct
19 Correct 254 ms 42232 KB Output is correct
20 Correct 321 ms 43896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 26360 KB Output is correct
2 Correct 74 ms 26488 KB Output is correct
3 Correct 73 ms 26488 KB Output is correct
4 Correct 71 ms 26360 KB Output is correct
5 Correct 72 ms 26484 KB Output is correct
6 Correct 72 ms 26488 KB Output is correct
7 Correct 78 ms 26488 KB Output is correct
8 Correct 73 ms 26420 KB Output is correct
9 Correct 71 ms 26360 KB Output is correct
10 Correct 74 ms 26360 KB Output is correct
11 Correct 286 ms 44280 KB Output is correct
12 Correct 320 ms 43896 KB Output is correct
13 Correct 283 ms 43260 KB Output is correct
14 Correct 279 ms 43256 KB Output is correct
15 Correct 294 ms 44280 KB Output is correct
16 Correct 300 ms 43384 KB Output is correct
17 Correct 288 ms 43384 KB Output is correct
18 Correct 267 ms 45304 KB Output is correct
19 Correct 254 ms 42232 KB Output is correct
20 Correct 321 ms 43896 KB Output is correct
21 Correct 320 ms 44340 KB Output is correct
22 Correct 337 ms 44280 KB Output is correct
23 Correct 318 ms 43256 KB Output is correct
24 Correct 331 ms 43260 KB Output is correct
25 Correct 316 ms 45252 KB Output is correct
26 Correct 330 ms 45200 KB Output is correct
27 Correct 320 ms 45304 KB Output is correct
28 Correct 279 ms 47736 KB Output is correct
29 Correct 284 ms 43896 KB Output is correct
30 Correct 331 ms 45944 KB Output is correct
31 Correct 320 ms 45432 KB Output is correct
32 Correct 312 ms 45048 KB Output is correct
33 Correct 286 ms 43896 KB Output is correct
34 Correct 300 ms 44068 KB Output is correct
35 Correct 326 ms 44152 KB Output is correct
36 Correct 284 ms 53880 KB Output is correct
37 Correct 329 ms 55960 KB Output is correct
38 Correct 294 ms 53880 KB Output is correct
39 Correct 327 ms 55032 KB Output is correct
40 Correct 304 ms 54904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 26360 KB Output is correct
2 Correct 74 ms 26488 KB Output is correct
3 Correct 73 ms 26488 KB Output is correct
4 Correct 71 ms 26360 KB Output is correct
5 Correct 72 ms 26484 KB Output is correct
6 Correct 72 ms 26488 KB Output is correct
7 Correct 78 ms 26488 KB Output is correct
8 Correct 73 ms 26420 KB Output is correct
9 Correct 71 ms 26360 KB Output is correct
10 Correct 74 ms 26360 KB Output is correct
11 Runtime error 119 ms 58608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 26360 KB Output is correct
2 Correct 74 ms 26488 KB Output is correct
3 Correct 73 ms 26488 KB Output is correct
4 Correct 71 ms 26360 KB Output is correct
5 Correct 72 ms 26484 KB Output is correct
6 Correct 72 ms 26488 KB Output is correct
7 Correct 78 ms 26488 KB Output is correct
8 Correct 73 ms 26420 KB Output is correct
9 Correct 71 ms 26360 KB Output is correct
10 Correct 74 ms 26360 KB Output is correct
11 Correct 286 ms 44280 KB Output is correct
12 Correct 320 ms 43896 KB Output is correct
13 Correct 283 ms 43260 KB Output is correct
14 Correct 279 ms 43256 KB Output is correct
15 Correct 294 ms 44280 KB Output is correct
16 Correct 300 ms 43384 KB Output is correct
17 Correct 288 ms 43384 KB Output is correct
18 Correct 267 ms 45304 KB Output is correct
19 Correct 254 ms 42232 KB Output is correct
20 Correct 321 ms 43896 KB Output is correct
21 Correct 320 ms 44340 KB Output is correct
22 Correct 337 ms 44280 KB Output is correct
23 Correct 318 ms 43256 KB Output is correct
24 Correct 331 ms 43260 KB Output is correct
25 Correct 316 ms 45252 KB Output is correct
26 Correct 330 ms 45200 KB Output is correct
27 Correct 320 ms 45304 KB Output is correct
28 Correct 279 ms 47736 KB Output is correct
29 Correct 284 ms 43896 KB Output is correct
30 Correct 331 ms 45944 KB Output is correct
31 Correct 320 ms 45432 KB Output is correct
32 Correct 312 ms 45048 KB Output is correct
33 Correct 286 ms 43896 KB Output is correct
34 Correct 300 ms 44068 KB Output is correct
35 Correct 326 ms 44152 KB Output is correct
36 Correct 284 ms 53880 KB Output is correct
37 Correct 329 ms 55960 KB Output is correct
38 Correct 294 ms 53880 KB Output is correct
39 Correct 327 ms 55032 KB Output is correct
40 Correct 304 ms 54904 KB Output is correct
41 Runtime error 119 ms 58608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Halted 0 ms 0 KB -