답안 #255185

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255185 2020-07-31T13:53:02 Z Atill83 Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
1795 ms 65536 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e6;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n, l, q;
string s;
int say[MAXN][2];
int ans[MAXN];

const int n37 = 2187;
const int n313 = 1594323;
int child[n313][2];
bool sub[n37][(1<<7)];
ll dp[n313];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    cin>>l>>q;

    cin>>s;

    for(int i = 0; i < q; i++){
        string t;
        cin>>t;
        for(int j = 0; j < min(l, 7); j++){
            say[i][0] += (t[j] == '?' ? 2 : t[j] - '0');
            say[i][0] *= 3;
        }
        say[i][0] /= 3;
        for(int j = 7; j < l; j++){
            say[i][1] += (t[j] == '?' ? 2 : t[j] - '0');
            say[i][1] *= 3;
        }
        say[i][1] /= 3;
    }

    for(int i = 0; i < n313; i++){
        int cur = i;
        child[i][0] = child[i][1] = -1;
        int cc = 1;
        for(int j = 0; j < 13; j++){
            if(cur % 3 == 2){
                child[i][0] = i - cc;
                child[i][1] = i - 2*cc;
                break;
            }
            cc *= 3;
            cur /= 3;
        }
    }


    for(int i = 0; i < n37; i++){
        for(int j = 0; j < (1<<7); j++){
            int cur1 = i, cur2 = j;
            bool tru = 1;
            for(int k = 0; k < 7; k++){
                if(cur1 % 3 != 2 && cur1 % 3 != cur2 % 2){
                    tru = 0;
                    break;
                }
                cur1 /= 3;
                cur2 /= 2;
            }
            sub[i][j] = tru;
        }
    }

    int rhs = max(0, l - 7);

    for(int j = 0; j < (1<<min(l, 7)); j++){
        
        for(int i = 0; i < n313; i++){
            if(child[i][0] == -1){
                int kal = 0;
                int cur = i;
                for(int k = 0; k < rhs; k++){
                    if(cur % 3) kal += (1<<k);
                    cur /= 3;
                }
                dp[i] = s[(j<<rhs) + kal] - '0';
            }else{
                dp[i] = dp[child[i][0]] + dp[child[i][1]];
            }
        }

        for(int i = 0; i < q; i++){
            if(!sub[say[i][0]][j]) continue;
            ans[i] += dp[say[i][1]];
        }
    }

    for(int i = 0; i < q; i++)
        cout<<ans[i]<<endl;


    

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# 결과 실행 시간 메모리 Grader output
1 Correct 331 ms 25720 KB Output is correct
2 Correct 318 ms 25596 KB Output is correct
3 Correct 399 ms 25592 KB Output is correct
4 Correct 433 ms 25720 KB Output is correct
5 Correct 338 ms 25656 KB Output is correct
6 Correct 323 ms 25592 KB Output is correct
7 Correct 318 ms 25592 KB Output is correct
8 Correct 320 ms 25656 KB Output is correct
9 Correct 320 ms 25592 KB Output is correct
10 Correct 328 ms 25688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 331 ms 25720 KB Output is correct
2 Correct 318 ms 25596 KB Output is correct
3 Correct 399 ms 25592 KB Output is correct
4 Correct 433 ms 25720 KB Output is correct
5 Correct 338 ms 25656 KB Output is correct
6 Correct 323 ms 25592 KB Output is correct
7 Correct 318 ms 25592 KB Output is correct
8 Correct 320 ms 25656 KB Output is correct
9 Correct 320 ms 25592 KB Output is correct
10 Correct 328 ms 25688 KB Output is correct
11 Correct 842 ms 46424 KB Output is correct
12 Correct 1027 ms 45948 KB Output is correct
13 Correct 922 ms 45176 KB Output is correct
14 Correct 907 ms 45304 KB Output is correct
15 Correct 950 ms 46456 KB Output is correct
16 Correct 926 ms 45432 KB Output is correct
17 Correct 922 ms 45432 KB Output is correct
18 Correct 664 ms 47372 KB Output is correct
19 Correct 702 ms 44512 KB Output is correct
20 Correct 896 ms 45944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 331 ms 25720 KB Output is correct
2 Correct 318 ms 25596 KB Output is correct
3 Correct 399 ms 25592 KB Output is correct
4 Correct 433 ms 25720 KB Output is correct
5 Correct 338 ms 25656 KB Output is correct
6 Correct 323 ms 25592 KB Output is correct
7 Correct 318 ms 25592 KB Output is correct
8 Correct 320 ms 25656 KB Output is correct
9 Correct 320 ms 25592 KB Output is correct
10 Correct 328 ms 25688 KB Output is correct
11 Correct 842 ms 46424 KB Output is correct
12 Correct 1027 ms 45948 KB Output is correct
13 Correct 922 ms 45176 KB Output is correct
14 Correct 907 ms 45304 KB Output is correct
15 Correct 950 ms 46456 KB Output is correct
16 Correct 926 ms 45432 KB Output is correct
17 Correct 922 ms 45432 KB Output is correct
18 Correct 664 ms 47372 KB Output is correct
19 Correct 702 ms 44512 KB Output is correct
20 Correct 896 ms 45944 KB Output is correct
21 Correct 1004 ms 46328 KB Output is correct
22 Correct 953 ms 46584 KB Output is correct
23 Correct 834 ms 45688 KB Output is correct
24 Correct 818 ms 45432 KB Output is correct
25 Correct 1127 ms 47480 KB Output is correct
26 Correct 881 ms 45944 KB Output is correct
27 Correct 914 ms 45920 KB Output is correct
28 Correct 696 ms 48504 KB Output is correct
29 Correct 692 ms 44156 KB Output is correct
30 Correct 929 ms 46200 KB Output is correct
31 Correct 909 ms 45688 KB Output is correct
32 Correct 835 ms 45688 KB Output is correct
33 Correct 845 ms 44152 KB Output is correct
34 Correct 1016 ms 44212 KB Output is correct
35 Correct 863 ms 44548 KB Output is correct
36 Correct 678 ms 42744 KB Output is correct
37 Correct 890 ms 44256 KB Output is correct
38 Correct 816 ms 41976 KB Output is correct
39 Correct 875 ms 42872 KB Output is correct
40 Correct 852 ms 42248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 331 ms 25720 KB Output is correct
2 Correct 318 ms 25596 KB Output is correct
3 Correct 399 ms 25592 KB Output is correct
4 Correct 433 ms 25720 KB Output is correct
5 Correct 338 ms 25656 KB Output is correct
6 Correct 323 ms 25592 KB Output is correct
7 Correct 318 ms 25592 KB Output is correct
8 Correct 320 ms 25656 KB Output is correct
9 Correct 320 ms 25592 KB Output is correct
10 Correct 328 ms 25688 KB Output is correct
11 Correct 461 ms 28504 KB Output is correct
12 Correct 394 ms 29592 KB Output is correct
13 Correct 400 ms 29592 KB Output is correct
14 Correct 429 ms 29576 KB Output is correct
15 Correct 421 ms 29720 KB Output is correct
16 Correct 437 ms 29592 KB Output is correct
17 Correct 403 ms 29592 KB Output is correct
18 Correct 396 ms 29836 KB Output is correct
19 Correct 373 ms 29464 KB Output is correct
20 Correct 406 ms 29720 KB Output is correct
21 Correct 478 ms 29592 KB Output is correct
22 Correct 472 ms 29592 KB Output is correct
23 Correct 451 ms 29592 KB Output is correct
24 Correct 394 ms 29592 KB Output is correct
25 Correct 403 ms 29592 KB Output is correct
26 Correct 364 ms 29592 KB Output is correct
27 Correct 409 ms 29720 KB Output is correct
28 Correct 391 ms 29472 KB Output is correct
29 Correct 442 ms 29592 KB Output is correct
30 Correct 400 ms 29592 KB Output is correct
31 Correct 390 ms 29592 KB Output is correct
32 Correct 469 ms 29592 KB Output is correct
33 Correct 432 ms 29592 KB Output is correct
34 Correct 379 ms 29460 KB Output is correct
35 Correct 402 ms 29580 KB Output is correct
36 Correct 411 ms 29592 KB Output is correct
37 Correct 396 ms 29592 KB Output is correct
38 Correct 442 ms 29584 KB Output is correct
39 Correct 408 ms 29668 KB Output is correct
40 Correct 452 ms 29588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 331 ms 25720 KB Output is correct
2 Correct 318 ms 25596 KB Output is correct
3 Correct 399 ms 25592 KB Output is correct
4 Correct 433 ms 25720 KB Output is correct
5 Correct 338 ms 25656 KB Output is correct
6 Correct 323 ms 25592 KB Output is correct
7 Correct 318 ms 25592 KB Output is correct
8 Correct 320 ms 25656 KB Output is correct
9 Correct 320 ms 25592 KB Output is correct
10 Correct 328 ms 25688 KB Output is correct
11 Correct 842 ms 46424 KB Output is correct
12 Correct 1027 ms 45948 KB Output is correct
13 Correct 922 ms 45176 KB Output is correct
14 Correct 907 ms 45304 KB Output is correct
15 Correct 950 ms 46456 KB Output is correct
16 Correct 926 ms 45432 KB Output is correct
17 Correct 922 ms 45432 KB Output is correct
18 Correct 664 ms 47372 KB Output is correct
19 Correct 702 ms 44512 KB Output is correct
20 Correct 896 ms 45944 KB Output is correct
21 Correct 1004 ms 46328 KB Output is correct
22 Correct 953 ms 46584 KB Output is correct
23 Correct 834 ms 45688 KB Output is correct
24 Correct 818 ms 45432 KB Output is correct
25 Correct 1127 ms 47480 KB Output is correct
26 Correct 881 ms 45944 KB Output is correct
27 Correct 914 ms 45920 KB Output is correct
28 Correct 696 ms 48504 KB Output is correct
29 Correct 692 ms 44156 KB Output is correct
30 Correct 929 ms 46200 KB Output is correct
31 Correct 909 ms 45688 KB Output is correct
32 Correct 835 ms 45688 KB Output is correct
33 Correct 845 ms 44152 KB Output is correct
34 Correct 1016 ms 44212 KB Output is correct
35 Correct 863 ms 44548 KB Output is correct
36 Correct 678 ms 42744 KB Output is correct
37 Correct 890 ms 44256 KB Output is correct
38 Correct 816 ms 41976 KB Output is correct
39 Correct 875 ms 42872 KB Output is correct
40 Correct 852 ms 42248 KB Output is correct
41 Correct 461 ms 28504 KB Output is correct
42 Correct 394 ms 29592 KB Output is correct
43 Correct 400 ms 29592 KB Output is correct
44 Correct 429 ms 29576 KB Output is correct
45 Correct 421 ms 29720 KB Output is correct
46 Correct 437 ms 29592 KB Output is correct
47 Correct 403 ms 29592 KB Output is correct
48 Correct 396 ms 29836 KB Output is correct
49 Correct 373 ms 29464 KB Output is correct
50 Correct 406 ms 29720 KB Output is correct
51 Correct 478 ms 29592 KB Output is correct
52 Correct 472 ms 29592 KB Output is correct
53 Correct 451 ms 29592 KB Output is correct
54 Correct 394 ms 29592 KB Output is correct
55 Correct 403 ms 29592 KB Output is correct
56 Correct 364 ms 29592 KB Output is correct
57 Correct 409 ms 29720 KB Output is correct
58 Correct 391 ms 29472 KB Output is correct
59 Correct 442 ms 29592 KB Output is correct
60 Correct 400 ms 29592 KB Output is correct
61 Correct 390 ms 29592 KB Output is correct
62 Correct 469 ms 29592 KB Output is correct
63 Correct 432 ms 29592 KB Output is correct
64 Correct 379 ms 29460 KB Output is correct
65 Correct 402 ms 29580 KB Output is correct
66 Correct 411 ms 29592 KB Output is correct
67 Correct 396 ms 29592 KB Output is correct
68 Correct 442 ms 29584 KB Output is correct
69 Correct 408 ms 29668 KB Output is correct
70 Correct 452 ms 29588 KB Output is correct
71 Correct 1027 ms 65164 KB Output is correct
72 Correct 1244 ms 65156 KB Output is correct
73 Correct 1261 ms 63760 KB Output is correct
74 Correct 1378 ms 64112 KB Output is correct
75 Correct 1483 ms 65536 KB Output is correct
76 Correct 1415 ms 64384 KB Output is correct
77 Correct 1373 ms 64168 KB Output is correct
78 Correct 785 ms 65536 KB Output is correct
79 Correct 828 ms 61976 KB Output is correct
80 Correct 1061 ms 65292 KB Output is correct
81 Correct 1607 ms 65248 KB Output is correct
82 Correct 1345 ms 64136 KB Output is correct
83 Correct 1061 ms 63324 KB Output is correct
84 Correct 1246 ms 64092 KB Output is correct
85 Correct 1795 ms 64220 KB Output is correct
86 Correct 798 ms 62068 KB Output is correct
87 Correct 1149 ms 64992 KB Output is correct
88 Correct 800 ms 62108 KB Output is correct
89 Correct 1161 ms 63720 KB Output is correct
90 Correct 1261 ms 64080 KB Output is correct
91 Correct 948 ms 63324 KB Output is correct
92 Correct 1391 ms 64368 KB Output is correct
93 Correct 1361 ms 64208 KB Output is correct
94 Correct 773 ms 62072 KB Output is correct
95 Correct 1331 ms 64128 KB Output is correct
96 Correct 1349 ms 64240 KB Output is correct
97 Correct 1400 ms 64172 KB Output is correct
98 Correct 1350 ms 64500 KB Output is correct
99 Correct 1322 ms 64344 KB Output is correct
100 Correct 1485 ms 64220 KB Output is correct