답안 #210493

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210493 2020-03-17T14:11:11 Z SamAnd Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
653 ms 38520 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 22, Q = 1000006;

int n, qq;
char a[(1 << N)];

bool so(const char a[], const char b[])
{
    for (int i = 1; i <= n; ++i)
    {
        if (a[i] != b[i])
            return a[i] < b[i];
    }
    return false;
}
struct ban
{
    int i;
    char u[N];
};
bool operator<(const ban& a, const ban& b)
{
    return so(a.u, b.u);
}
ban b[Q];

int* t[N];

int ans[Q];

void rec(int i, int x, int u)
{
    if (i == n + 1)
    {
        ans[b[u].i] += t[n][x];
        return;
    }
    if (b[u].u[i] == '0')
        rec(i + 1, x, u);
    else if (b[u].u[i] == '1')
        rec(i + 1, x + (1 << (n - i)), u);
    else
    {
        rec(i + 1, x, u);
        rec(i + 1, x + (1 << (n - i)), u);
    }
}

int main()
{
    scanf("%d%d", &n, &qq);
    scanf(" %s", a);
    for (int i = 0; i < (1 << n); ++i)
        a[i] -= '0';
    for (int i = 0; i < qq; ++i)
    {
        b[i].i = i;
        scanf(" %s", (b[i].u + 1));
    }
    sort(b, b + qq);
    for (int j = 0; j <= n; ++j)
        t[j] = new int[(1 << (n - j))];
    for (int k = 0; k < (1 << n); ++k)
        t[0][k] = a[k];
    for (int i = 0; i < qq; ++i)
    {
        int s = 14;
        for (int j = 1; j <= min(n, 13); ++j)
        {
            if (i == 0 || b[i].u[j] != b[i - 1].u[j])
            {
                s = j;
                break;
            }
        }
        for (int j = s; j <= min(n, 13); ++j)
        {
            if (b[i].u[j] == '0')
            {
                for (int k = 0; k < (1 << (n - j)); ++k)
                {
                    t[j][k] = t[j - 1][k];
                }
            }
            else if (b[i].u[j] == '1')
            {
                for (int k = 0; k < (1 << (n - j)); ++k)
                {
                    t[j][k] = t[j - 1][k + (1 << (n - j))];
                }
            }
            else
            {
                for (int k = 0; k < (1 << (n - j)); ++k)
                {
                    t[j][k] = t[j - 1][k] + t[j - 1][k + (1 << (n - j))];
                }
            }
        }
        if (n <= 13)
        {
            ans[b[i].i] = t[n][0];
            continue;
        }
        rec(14, 0, i);
    }
    for (int i = 0; i < qq; ++i)
        printf("%d\n", ans[i]);
    return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &qq);
     ~~~~~^~~~~~~~~~~~~~~~~
snake_escaping.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %s", a);
     ~~~~~^~~~~~~~~~
snake_escaping.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %s", (b[i].u + 1));
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 450 ms 36344 KB Output is correct
12 Correct 514 ms 36088 KB Output is correct
13 Correct 511 ms 35156 KB Output is correct
14 Correct 502 ms 35320 KB Output is correct
15 Correct 498 ms 36472 KB Output is correct
16 Correct 539 ms 35448 KB Output is correct
17 Correct 560 ms 35448 KB Output is correct
18 Correct 388 ms 37240 KB Output is correct
19 Correct 474 ms 34296 KB Output is correct
20 Correct 494 ms 36092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 450 ms 36344 KB Output is correct
12 Correct 514 ms 36088 KB Output is correct
13 Correct 511 ms 35156 KB Output is correct
14 Correct 502 ms 35320 KB Output is correct
15 Correct 498 ms 36472 KB Output is correct
16 Correct 539 ms 35448 KB Output is correct
17 Correct 560 ms 35448 KB Output is correct
18 Correct 388 ms 37240 KB Output is correct
19 Correct 474 ms 34296 KB Output is correct
20 Correct 494 ms 36092 KB Output is correct
21 Correct 507 ms 36472 KB Output is correct
22 Correct 559 ms 36472 KB Output is correct
23 Correct 614 ms 35576 KB Output is correct
24 Correct 594 ms 35424 KB Output is correct
25 Correct 574 ms 37368 KB Output is correct
26 Correct 631 ms 35960 KB Output is correct
27 Correct 653 ms 35960 KB Output is correct
28 Correct 428 ms 38520 KB Output is correct
29 Correct 553 ms 34424 KB Output is correct
30 Correct 566 ms 36732 KB Output is correct
31 Correct 615 ms 36472 KB Output is correct
32 Correct 584 ms 36472 KB Output is correct
33 Correct 559 ms 35320 KB Output is correct
34 Correct 610 ms 35448 KB Output is correct
35 Correct 649 ms 35832 KB Output is correct
36 Correct 400 ms 34400 KB Output is correct
37 Correct 513 ms 36344 KB Output is correct
38 Correct 563 ms 34296 KB Output is correct
39 Correct 621 ms 35576 KB Output is correct
40 Correct 581 ms 35320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Incorrect 74 ms 11896 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 450 ms 36344 KB Output is correct
12 Correct 514 ms 36088 KB Output is correct
13 Correct 511 ms 35156 KB Output is correct
14 Correct 502 ms 35320 KB Output is correct
15 Correct 498 ms 36472 KB Output is correct
16 Correct 539 ms 35448 KB Output is correct
17 Correct 560 ms 35448 KB Output is correct
18 Correct 388 ms 37240 KB Output is correct
19 Correct 474 ms 34296 KB Output is correct
20 Correct 494 ms 36092 KB Output is correct
21 Correct 507 ms 36472 KB Output is correct
22 Correct 559 ms 36472 KB Output is correct
23 Correct 614 ms 35576 KB Output is correct
24 Correct 594 ms 35424 KB Output is correct
25 Correct 574 ms 37368 KB Output is correct
26 Correct 631 ms 35960 KB Output is correct
27 Correct 653 ms 35960 KB Output is correct
28 Correct 428 ms 38520 KB Output is correct
29 Correct 553 ms 34424 KB Output is correct
30 Correct 566 ms 36732 KB Output is correct
31 Correct 615 ms 36472 KB Output is correct
32 Correct 584 ms 36472 KB Output is correct
33 Correct 559 ms 35320 KB Output is correct
34 Correct 610 ms 35448 KB Output is correct
35 Correct 649 ms 35832 KB Output is correct
36 Correct 400 ms 34400 KB Output is correct
37 Correct 513 ms 36344 KB Output is correct
38 Correct 563 ms 34296 KB Output is correct
39 Correct 621 ms 35576 KB Output is correct
40 Correct 581 ms 35320 KB Output is correct
41 Incorrect 74 ms 11896 KB Output isn't correct
42 Halted 0 ms 0 KB -