Submission #587048

# Submission time Handle Problem Language Result Execution time Memory
587048 2022-07-01T09:15:43 Z eecs Ljetopica (COI19_ljetopica) C++17
100 / 100
187 ms 476 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1010, P = 1000000007;
int n, K, pw[maxn];
string dir, A, B;

typedef array<int, 2> arr;
arr f[maxn][2][2][2], g[maxn][2][2][2];

void operator += (arr &A, const arr &B) {
    A = {(A[0] + B[0]) % P, (A[1] + B[1]) % P};
}
arr operator * (const arr &A, const arr &B) {
    return {1LL * A[0] * B[0] % P, (1LL * A[0] * B[1] + 1LL * A[1] * B[0]) % P};
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> K;
    for (int i = pw[0] = 1; i < n; i++) {
        pw[i] = 2 * pw[i - 1] % P;
    }
    cin >> dir >> A >> B;
    f[0][0][0][0] = f[0][1][0][0] = {1, pw[n - 1]};
    for (int i = 0; i < n - 1; i++) {
        memset(g, 0, sizeof(g));
        for (int j = 0; j <= K; j++) for (int k : {0, 1}) {
            for (int a : {0, 1}) for (int b : {0, 1}) {
                for (int l : {0, 1}) {
                    char c = (dir[i] == 'L') ^ k ^ l ? '0' : '1';
                    if (!a && c < A[i + 1]) continue;
                    if (!b && c > B[i + 1]) continue;
                    g[j + l][k ^ l][a | (c > A[i + 1])][b | (c < B[i + 1])]
                        += f[j][k][a][b] * arr{1, (c - '0') * pw[n - i - 2]};
                }
            }
        }
        swap(f, g);
    }
    int ans = 0;
    for (int i : {0, 1}) for (int j : {0, 1}) for (int k : {0, 1}) {
        (ans += f[K][i][j][k][1]) %= P;
    }
    cout << ans << "\n";
    return 0;
}

Compilation message

ljetopica.cpp: In function 'arr operator*(const arr&, const arr&)':
ljetopica.cpp:15:31: warning: narrowing conversion of '(((1 * ((long long int)((int)(& A)->std::array<int, 2>::operator[](0)))) * ((long long int)((int)(& B)->std::array<int, 2>::operator[](0)))) % ((long long int)((int)P)))' from 'long long int' to 'int' [-Wnarrowing]
   15 |     return {1LL * A[0] * B[0] % P, (1LL * A[0] * B[1] + 1LL * A[1] * B[0]) % P};
      |             ~~~~~~~~~~~~~~~~~~^~~
ljetopica.cpp:15:76: warning: narrowing conversion of '((((1 * ((long long int)((int)(& A)->std::array<int, 2>::operator[](0)))) * ((long long int)((int)(& B)->std::array<int, 2>::operator[](1)))) + ((1 * ((long long int)((int)(& A)->std::array<int, 2>::operator[](1)))) * ((long long int)((int)(& B)->std::array<int, 2>::operator[](0))))) % ((long long int)((int)P)))' from 'long long int' to 'int' [-Wnarrowing]
   15 |     return {1LL * A[0] * B[0] % P, (1LL * A[0] * B[1] + 1LL * A[1] * B[0]) % P};
      |                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 340 KB Output is correct
2 Correct 12 ms 340 KB Output is correct
3 Correct 13 ms 340 KB Output is correct
4 Correct 11 ms 340 KB Output is correct
5 Correct 11 ms 340 KB Output is correct
6 Correct 11 ms 460 KB Output is correct
7 Correct 9 ms 460 KB Output is correct
8 Correct 14 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 452 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 436 KB Output is correct
2 Correct 90 ms 340 KB Output is correct
3 Correct 107 ms 340 KB Output is correct
4 Correct 187 ms 440 KB Output is correct
5 Correct 86 ms 440 KB Output is correct
6 Correct 169 ms 440 KB Output is correct
7 Correct 58 ms 476 KB Output is correct
8 Correct 98 ms 340 KB Output is correct
9 Correct 20 ms 456 KB Output is correct
10 Correct 113 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 340 KB Output is correct
2 Correct 12 ms 340 KB Output is correct
3 Correct 13 ms 340 KB Output is correct
4 Correct 11 ms 340 KB Output is correct
5 Correct 11 ms 340 KB Output is correct
6 Correct 11 ms 460 KB Output is correct
7 Correct 9 ms 460 KB Output is correct
8 Correct 14 ms 452 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 452 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 125 ms 436 KB Output is correct
25 Correct 90 ms 340 KB Output is correct
26 Correct 107 ms 340 KB Output is correct
27 Correct 187 ms 440 KB Output is correct
28 Correct 86 ms 440 KB Output is correct
29 Correct 169 ms 440 KB Output is correct
30 Correct 58 ms 476 KB Output is correct
31 Correct 98 ms 340 KB Output is correct
32 Correct 20 ms 456 KB Output is correct
33 Correct 113 ms 340 KB Output is correct
34 Correct 125 ms 444 KB Output is correct
35 Correct 50 ms 336 KB Output is correct
36 Correct 75 ms 436 KB Output is correct
37 Correct 166 ms 444 KB Output is correct
38 Correct 36 ms 440 KB Output is correct
39 Correct 133 ms 340 KB Output is correct
40 Correct 30 ms 340 KB Output is correct
41 Correct 98 ms 444 KB Output is correct
42 Correct 123 ms 444 KB Output is correct
43 Correct 116 ms 440 KB Output is correct
44 Correct 137 ms 440 KB Output is correct
45 Correct 48 ms 460 KB Output is correct
46 Correct 131 ms 444 KB Output is correct
47 Correct 122 ms 436 KB Output is correct
48 Correct 68 ms 340 KB Output is correct
49 Correct 18 ms 340 KB Output is correct
50 Correct 135 ms 436 KB Output is correct
51 Correct 70 ms 420 KB Output is correct
52 Correct 83 ms 440 KB Output is correct
53 Correct 155 ms 340 KB Output is correct
54 Correct 51 ms 440 KB Output is correct
55 Correct 143 ms 440 KB Output is correct
56 Correct 149 ms 440 KB Output is correct
57 Correct 25 ms 460 KB Output is correct
58 Correct 117 ms 340 KB Output is correct