답안 #587052

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587052 2022-07-01T09:17:08 Z eecs Ljetopica (COI19_ljetopica) C++17
100 / 100
64 ms 460 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}) if (f[j][k][a][b][0]) {
                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};
      |                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 452 KB Output is correct
2 Correct 12 ms 340 KB Output is correct
3 Correct 12 ms 452 KB Output is correct
4 Correct 12 ms 456 KB Output is correct
5 Correct 10 ms 460 KB Output is correct
6 Correct 11 ms 340 KB Output is correct
7 Correct 10 ms 456 KB Output is correct
8 Correct 8 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 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 340 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
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 436 KB Output is correct
2 Correct 34 ms 436 KB Output is correct
3 Correct 37 ms 448 KB Output is correct
4 Correct 53 ms 340 KB Output is correct
5 Correct 34 ms 432 KB Output is correct
6 Correct 64 ms 436 KB Output is correct
7 Correct 30 ms 456 KB Output is correct
8 Correct 39 ms 340 KB Output is correct
9 Correct 14 ms 340 KB Output is correct
10 Correct 36 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 452 KB Output is correct
2 Correct 12 ms 340 KB Output is correct
3 Correct 12 ms 452 KB Output is correct
4 Correct 12 ms 456 KB Output is correct
5 Correct 10 ms 460 KB Output is correct
6 Correct 11 ms 340 KB Output is correct
7 Correct 10 ms 456 KB Output is correct
8 Correct 8 ms 444 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 340 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 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 45 ms 436 KB Output is correct
25 Correct 34 ms 436 KB Output is correct
26 Correct 37 ms 448 KB Output is correct
27 Correct 53 ms 340 KB Output is correct
28 Correct 34 ms 432 KB Output is correct
29 Correct 64 ms 436 KB Output is correct
30 Correct 30 ms 456 KB Output is correct
31 Correct 39 ms 340 KB Output is correct
32 Correct 14 ms 340 KB Output is correct
33 Correct 36 ms 340 KB Output is correct
34 Correct 47 ms 340 KB Output is correct
35 Correct 28 ms 456 KB Output is correct
36 Correct 36 ms 340 KB Output is correct
37 Correct 28 ms 340 KB Output is correct
38 Correct 40 ms 436 KB Output is correct
39 Correct 45 ms 340 KB Output is correct
40 Correct 20 ms 340 KB Output is correct
41 Correct 39 ms 340 KB Output is correct
42 Correct 44 ms 340 KB Output is correct
43 Correct 43 ms 436 KB Output is correct
44 Correct 49 ms 440 KB Output is correct
45 Correct 27 ms 460 KB Output is correct
46 Correct 42 ms 460 KB Output is correct
47 Correct 42 ms 340 KB Output is correct
48 Correct 34 ms 436 KB Output is correct
49 Correct 14 ms 340 KB Output is correct
50 Correct 46 ms 340 KB Output is correct
51 Correct 31 ms 340 KB Output is correct
52 Correct 32 ms 340 KB Output is correct
53 Correct 51 ms 432 KB Output is correct
54 Correct 27 ms 340 KB Output is correct
55 Correct 50 ms 460 KB Output is correct
56 Correct 54 ms 432 KB Output is correct
57 Correct 18 ms 340 KB Output is correct
58 Correct 48 ms 436 KB Output is correct