답안 #255706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255706 2020-08-01T15:45:29 Z egekabas Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
1676 ms 62616 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 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, 7);
    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){
        
    }
    for(int i = 0; i < (1<<a); ++i){
        for(int j = 0; j < n13; ++j){
            if(child[j][0] == -1){
                dp[j] = 0;
                int val = j;
                int ret = 0;
                for(int k = 0; val > 0; ++k){
                    ret += (1<<k)*(val%3 > 0);
                    val /= 3;
                }
                if(ret + (1<<b)*i < s.size())
                    dp[j] = s[ret+(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:92:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(ret + (1<<b)*i < s.size())
                    ~~~~~~~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 20344 KB Output is correct
2 Correct 337 ms 20240 KB Output is correct
3 Correct 357 ms 20216 KB Output is correct
4 Correct 339 ms 20244 KB Output is correct
5 Correct 325 ms 20348 KB Output is correct
6 Correct 323 ms 20216 KB Output is correct
7 Correct 345 ms 20240 KB Output is correct
8 Correct 360 ms 20216 KB Output is correct
9 Correct 379 ms 20216 KB Output is correct
10 Correct 371 ms 20344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 20344 KB Output is correct
2 Correct 337 ms 20240 KB Output is correct
3 Correct 357 ms 20216 KB Output is correct
4 Correct 339 ms 20244 KB Output is correct
5 Correct 325 ms 20348 KB Output is correct
6 Correct 323 ms 20216 KB Output is correct
7 Correct 345 ms 20240 KB Output is correct
8 Correct 360 ms 20216 KB Output is correct
9 Correct 379 ms 20216 KB Output is correct
10 Correct 371 ms 20344 KB Output is correct
11 Correct 947 ms 36344 KB Output is correct
12 Correct 942 ms 35960 KB Output is correct
13 Correct 889 ms 35332 KB Output is correct
14 Correct 1040 ms 35412 KB Output is correct
15 Correct 1022 ms 36276 KB Output is correct
16 Correct 1002 ms 35488 KB Output is correct
17 Correct 982 ms 35448 KB Output is correct
18 Correct 667 ms 37496 KB Output is correct
19 Correct 730 ms 34296 KB Output is correct
20 Correct 934 ms 35960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 20344 KB Output is correct
2 Correct 337 ms 20240 KB Output is correct
3 Correct 357 ms 20216 KB Output is correct
4 Correct 339 ms 20244 KB Output is correct
5 Correct 325 ms 20348 KB Output is correct
6 Correct 323 ms 20216 KB Output is correct
7 Correct 345 ms 20240 KB Output is correct
8 Correct 360 ms 20216 KB Output is correct
9 Correct 379 ms 20216 KB Output is correct
10 Correct 371 ms 20344 KB Output is correct
11 Correct 947 ms 36344 KB Output is correct
12 Correct 942 ms 35960 KB Output is correct
13 Correct 889 ms 35332 KB Output is correct
14 Correct 1040 ms 35412 KB Output is correct
15 Correct 1022 ms 36276 KB Output is correct
16 Correct 1002 ms 35488 KB Output is correct
17 Correct 982 ms 35448 KB Output is correct
18 Correct 667 ms 37496 KB Output is correct
19 Correct 730 ms 34296 KB Output is correct
20 Correct 934 ms 35960 KB Output is correct
21 Correct 938 ms 36532 KB Output is correct
22 Correct 998 ms 36396 KB Output is correct
23 Correct 987 ms 35452 KB Output is correct
24 Correct 952 ms 35448 KB Output is correct
25 Correct 1070 ms 37468 KB Output is correct
26 Correct 1081 ms 35832 KB Output is correct
27 Correct 1018 ms 35708 KB Output is correct
28 Correct 676 ms 38084 KB Output is correct
29 Correct 725 ms 33956 KB Output is correct
30 Correct 983 ms 36228 KB Output is correct
31 Correct 972 ms 36128 KB Output is correct
32 Correct 971 ms 36092 KB Output is correct
33 Correct 875 ms 35064 KB Output is correct
34 Correct 1042 ms 35264 KB Output is correct
35 Correct 1008 ms 35704 KB Output is correct
36 Correct 614 ms 34168 KB Output is correct
37 Correct 936 ms 36216 KB Output is correct
38 Correct 775 ms 34296 KB Output is correct
39 Correct 937 ms 35448 KB Output is correct
40 Correct 965 ms 35192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 20344 KB Output is correct
2 Correct 337 ms 20240 KB Output is correct
3 Correct 357 ms 20216 KB Output is correct
4 Correct 339 ms 20244 KB Output is correct
5 Correct 325 ms 20348 KB Output is correct
6 Correct 323 ms 20216 KB Output is correct
7 Correct 345 ms 20240 KB Output is correct
8 Correct 360 ms 20216 KB Output is correct
9 Correct 379 ms 20216 KB Output is correct
10 Correct 371 ms 20344 KB Output is correct
11 Correct 397 ms 22228 KB Output is correct
12 Correct 366 ms 24216 KB Output is correct
13 Correct 363 ms 24216 KB Output is correct
14 Correct 375 ms 24216 KB Output is correct
15 Correct 387 ms 24284 KB Output is correct
16 Correct 369 ms 24216 KB Output is correct
17 Correct 378 ms 24276 KB Output is correct
18 Correct 342 ms 24472 KB Output is correct
19 Correct 340 ms 24016 KB Output is correct
20 Correct 367 ms 24276 KB Output is correct
21 Correct 381 ms 24276 KB Output is correct
22 Correct 372 ms 24220 KB Output is correct
23 Correct 354 ms 24092 KB Output is correct
24 Correct 367 ms 24216 KB Output is correct
25 Correct 367 ms 24220 KB Output is correct
26 Correct 336 ms 24088 KB Output is correct
27 Correct 359 ms 24216 KB Output is correct
28 Correct 347 ms 24052 KB Output is correct
29 Correct 360 ms 24216 KB Output is correct
30 Correct 374 ms 24216 KB Output is correct
31 Correct 395 ms 24148 KB Output is correct
32 Correct 376 ms 24216 KB Output is correct
33 Correct 374 ms 24216 KB Output is correct
34 Correct 335 ms 24088 KB Output is correct
35 Correct 372 ms 24272 KB Output is correct
36 Correct 374 ms 24244 KB Output is correct
37 Correct 415 ms 24216 KB Output is correct
38 Correct 477 ms 24216 KB Output is correct
39 Correct 411 ms 24216 KB Output is correct
40 Correct 411 ms 24220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 20344 KB Output is correct
2 Correct 337 ms 20240 KB Output is correct
3 Correct 357 ms 20216 KB Output is correct
4 Correct 339 ms 20244 KB Output is correct
5 Correct 325 ms 20348 KB Output is correct
6 Correct 323 ms 20216 KB Output is correct
7 Correct 345 ms 20240 KB Output is correct
8 Correct 360 ms 20216 KB Output is correct
9 Correct 379 ms 20216 KB Output is correct
10 Correct 371 ms 20344 KB Output is correct
11 Correct 947 ms 36344 KB Output is correct
12 Correct 942 ms 35960 KB Output is correct
13 Correct 889 ms 35332 KB Output is correct
14 Correct 1040 ms 35412 KB Output is correct
15 Correct 1022 ms 36276 KB Output is correct
16 Correct 1002 ms 35488 KB Output is correct
17 Correct 982 ms 35448 KB Output is correct
18 Correct 667 ms 37496 KB Output is correct
19 Correct 730 ms 34296 KB Output is correct
20 Correct 934 ms 35960 KB Output is correct
21 Correct 938 ms 36532 KB Output is correct
22 Correct 998 ms 36396 KB Output is correct
23 Correct 987 ms 35452 KB Output is correct
24 Correct 952 ms 35448 KB Output is correct
25 Correct 1070 ms 37468 KB Output is correct
26 Correct 1081 ms 35832 KB Output is correct
27 Correct 1018 ms 35708 KB Output is correct
28 Correct 676 ms 38084 KB Output is correct
29 Correct 725 ms 33956 KB Output is correct
30 Correct 983 ms 36228 KB Output is correct
31 Correct 972 ms 36128 KB Output is correct
32 Correct 971 ms 36092 KB Output is correct
33 Correct 875 ms 35064 KB Output is correct
34 Correct 1042 ms 35264 KB Output is correct
35 Correct 1008 ms 35704 KB Output is correct
36 Correct 614 ms 34168 KB Output is correct
37 Correct 936 ms 36216 KB Output is correct
38 Correct 775 ms 34296 KB Output is correct
39 Correct 937 ms 35448 KB Output is correct
40 Correct 965 ms 35192 KB Output is correct
41 Correct 397 ms 22228 KB Output is correct
42 Correct 366 ms 24216 KB Output is correct
43 Correct 363 ms 24216 KB Output is correct
44 Correct 375 ms 24216 KB Output is correct
45 Correct 387 ms 24284 KB Output is correct
46 Correct 369 ms 24216 KB Output is correct
47 Correct 378 ms 24276 KB Output is correct
48 Correct 342 ms 24472 KB Output is correct
49 Correct 340 ms 24016 KB Output is correct
50 Correct 367 ms 24276 KB Output is correct
51 Correct 381 ms 24276 KB Output is correct
52 Correct 372 ms 24220 KB Output is correct
53 Correct 354 ms 24092 KB Output is correct
54 Correct 367 ms 24216 KB Output is correct
55 Correct 367 ms 24220 KB Output is correct
56 Correct 336 ms 24088 KB Output is correct
57 Correct 359 ms 24216 KB Output is correct
58 Correct 347 ms 24052 KB Output is correct
59 Correct 360 ms 24216 KB Output is correct
60 Correct 374 ms 24216 KB Output is correct
61 Correct 395 ms 24148 KB Output is correct
62 Correct 376 ms 24216 KB Output is correct
63 Correct 374 ms 24216 KB Output is correct
64 Correct 335 ms 24088 KB Output is correct
65 Correct 372 ms 24272 KB Output is correct
66 Correct 374 ms 24244 KB Output is correct
67 Correct 415 ms 24216 KB Output is correct
68 Correct 477 ms 24216 KB Output is correct
69 Correct 411 ms 24216 KB Output is correct
70 Correct 411 ms 24220 KB Output is correct
71 Correct 1042 ms 59728 KB Output is correct
72 Correct 1147 ms 59796 KB Output is correct
73 Correct 1221 ms 58392 KB Output is correct
74 Correct 1439 ms 58652 KB Output is correct
75 Correct 1451 ms 60656 KB Output is correct
76 Correct 1372 ms 59032 KB Output is correct
77 Correct 1379 ms 58776 KB Output is correct
78 Correct 762 ms 62616 KB Output is correct
79 Correct 815 ms 56600 KB Output is correct
80 Correct 1094 ms 59796 KB Output is correct
81 Correct 1555 ms 59780 KB Output is correct
82 Correct 1268 ms 58644 KB Output is correct
83 Correct 916 ms 57752 KB Output is correct
84 Correct 1224 ms 58648 KB Output is correct
85 Correct 1462 ms 58744 KB Output is correct
86 Correct 687 ms 56616 KB Output is correct
87 Correct 1127 ms 59712 KB Output is correct
88 Correct 824 ms 56500 KB Output is correct
89 Correct 1156 ms 58228 KB Output is correct
90 Correct 1349 ms 58648 KB Output is correct
91 Correct 961 ms 57872 KB Output is correct
92 Correct 1338 ms 58900 KB Output is correct
93 Correct 1604 ms 58736 KB Output is correct
94 Correct 736 ms 56580 KB Output is correct
95 Correct 1270 ms 58776 KB Output is correct
96 Correct 1332 ms 58772 KB Output is correct
97 Correct 1353 ms 58864 KB Output is correct
98 Correct 1303 ms 58704 KB Output is correct
99 Correct 1676 ms 58836 KB Output is correct
100 Correct 1346 ms 58760 KB Output is correct