답안 #131114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
131114 2019-07-16T13:58:28 Z BThero Ljetopica (COI19_ljetopica) C++17
100 / 100
91 ms 31992 KB
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;   
typedef pair<int, int> pii;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MAXN = (int)1e3 + 5;
const int MOD = (int)1e9 + 7;

int cnt[2][2][MAXN][MAXN];

int sum[2][2][MAXN][MAXN];

string s, A, B;

int n, k;

int addMod(int a, int b, int m = MOD) {
    a += b;

    if (m <= a) {
        a -= m;
    }

    return a;
}

int mulMod(int a, int b, int m = MOD) {
    return a * 1ll * b % m;
}

void upd(int &a, int b) {
    a = addMod(a, b);
}

int L(int fl, int le, int pos, int u) {
    return mulMod(sum[fl][le][pos][u], 2);
}

int R(int fl, int le, int pos, int u) {
    return addMod(L(fl, le, pos, u), cnt[fl][le][pos][u]);
}

void calc(string t) {
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int fl = 0; fl < 2; ++fl) {
                for (int le = 0; le < 2; ++le) {
                    cnt[fl][le][i][j] = 0;
                    sum[fl][le][i][j] = 0;
                }
            }
        }
    }

    if (t[0] == '0') {
        return;
    }

    cnt[0][0][0][0] = 1;
    sum[0][0][0][0] = 1;
    cnt[1][0][0][0] = 1;
    sum[1][0][0][0] = 1;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= k; ++j) {
            // less = 1

            upd(cnt[0][1][i + 1][j], cnt[0][1][i][j]);
            upd(cnt[1][1][i + 1][j], cnt[1][1][i][j]);
            upd(cnt[1][1][i + 1][j + 1], cnt[0][1][i][j]);
            upd(cnt[0][1][i + 1][j + 1], cnt[1][1][i][j]);

            // less = 0

            if (s[i + 1] == 'L') {
                if (t[i + 1] == '0') {
                    upd(cnt[0][0][i + 1][j], cnt[0][0][i][j]);
                    upd(cnt[0][0][i + 1][j + 1], cnt[1][0][i][j]);
                }
                else {
                    upd(cnt[0][1][i + 1][j], cnt[0][0][i][j]);
                    upd(cnt[0][1][i + 1][j + 1], cnt[1][0][i][j]);
                    upd(cnt[1][0][i + 1][j], cnt[1][0][i][j]);
                    upd(cnt[1][0][i + 1][j + 1], cnt[0][0][i][j]);
                }
            }
            else {
                if (t[i + 1] == '0') {
                    upd(cnt[1][0][i + 1][j], cnt[1][0][i][j]);
                    upd(cnt[1][0][i + 1][j + 1], cnt[0][0][i][j]);
                }
                else {
                    upd(cnt[0][0][i + 1][j], cnt[0][0][i][j]);
                    upd(cnt[0][0][i + 1][j + 1], cnt[1][0][i][j]);
                    upd(cnt[1][1][i + 1][j], cnt[1][0][i][j]);
                    upd(cnt[1][1][i + 1][j + 1], cnt[0][0][i][j]);
                }
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= k; ++j) {
            if (s[i + 1] == 'L') {
                upd(sum[0][1][i + 1][j], L(0, 1, i, j));
                upd(sum[0][1][i + 1][j + 1], L(1, 1, i, j));
                upd(sum[1][1][i + 1][j + 1], R(0, 1, i, j));
                upd(sum[1][1][i + 1][j], R(1, 1, i, j));

                if (t[i + 1] == '0') {
                    upd(sum[0][0][i + 1][j], L(0, 0, i, j));
                    upd(sum[0][0][i + 1][j + 1], L(1, 0, i, j));
                }
                else {
                    upd(sum[0][1][i + 1][j], L(0, 0, i, j));
                    upd(sum[0][1][i + 1][j + 1], L(1, 0, i, j));
                    upd(sum[1][0][i + 1][j], R(1, 0, i, j));
                    upd(sum[1][0][i + 1][j + 1], R(0, 0, i, j));
                }
            }
            else {
                upd(sum[0][1][i + 1][j], R(0, 1, i, j));
                upd(sum[0][1][i + 1][j + 1], R(1, 1, i, j));
                upd(sum[1][1][i + 1][j + 1], L(0, 1, i, j));
                upd(sum[1][1][i + 1][j], L(1, 1, i, j));

                if (t[i + 1] == '0') {
                    upd(sum[1][0][i + 1][j], L(1, 0, i, j));
                    upd(sum[1][0][i + 1][j + 1], L(0, 0, i, j));
                }
                else {
                    upd(sum[0][0][i + 1][j], R(0, 0, i, j));
                    upd(sum[0][0][i + 1][j + 1], R(1, 0, i, j));
                    upd(sum[1][1][i + 1][j], L(1, 0, i, j));
                    upd(sum[1][1][i + 1][j + 1], L(0, 0, i, j));
                }
            }
        }
    }
}

void solve() {
    scanf("%d %d", &n, &k);
    cin >> s >> A >> B;
    s = '#' + s;
    int ans = 0;

    calc(B);
    ans = addMod(ans, sum[0][0][n - 1][k]);
    ans = addMod(ans, sum[0][1][n - 1][k]);
    ans = addMod(ans, sum[1][0][n - 1][k]);
    ans = addMod(ans, sum[1][1][n - 1][k]);
    calc(A);
    ans = addMod(ans, MOD - sum[0][1][n - 1][k]);
    ans = addMod(ans, MOD - sum[1][1][n - 1][k]);

    printf("%d\n", ans);
}

int main() {
    #ifdef IOI
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Compilation message

ljetopica.cpp: In function 'void solve()':
ljetopica.cpp:163:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 31864 KB Output is correct
2 Correct 40 ms 30328 KB Output is correct
3 Correct 37 ms 28664 KB Output is correct
4 Correct 35 ms 27128 KB Output is correct
5 Correct 32 ms 25464 KB Output is correct
6 Correct 29 ms 24056 KB Output is correct
7 Correct 28 ms 22392 KB Output is correct
8 Correct 26 ms 20856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1204 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 2 ms 1020 KB Output is correct
10 Correct 2 ms 1016 KB Output is correct
11 Correct 2 ms 1016 KB Output is correct
12 Correct 2 ms 1020 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 3 ms 1016 KB Output is correct
15 Correct 3 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 31864 KB Output is correct
2 Correct 64 ms 31892 KB Output is correct
3 Correct 66 ms 31808 KB Output is correct
4 Correct 90 ms 31896 KB Output is correct
5 Correct 62 ms 31836 KB Output is correct
6 Correct 91 ms 31864 KB Output is correct
7 Correct 55 ms 31836 KB Output is correct
8 Correct 66 ms 31864 KB Output is correct
9 Correct 44 ms 31864 KB Output is correct
10 Correct 63 ms 31864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 31864 KB Output is correct
2 Correct 40 ms 30328 KB Output is correct
3 Correct 37 ms 28664 KB Output is correct
4 Correct 35 ms 27128 KB Output is correct
5 Correct 32 ms 25464 KB Output is correct
6 Correct 29 ms 24056 KB Output is correct
7 Correct 28 ms 22392 KB Output is correct
8 Correct 26 ms 20856 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1204 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 2 ms 1020 KB Output is correct
18 Correct 2 ms 1016 KB Output is correct
19 Correct 2 ms 1016 KB Output is correct
20 Correct 2 ms 1020 KB Output is correct
21 Correct 3 ms 1144 KB Output is correct
22 Correct 3 ms 1016 KB Output is correct
23 Correct 3 ms 1016 KB Output is correct
24 Correct 73 ms 31864 KB Output is correct
25 Correct 64 ms 31892 KB Output is correct
26 Correct 66 ms 31808 KB Output is correct
27 Correct 90 ms 31896 KB Output is correct
28 Correct 62 ms 31836 KB Output is correct
29 Correct 91 ms 31864 KB Output is correct
30 Correct 55 ms 31836 KB Output is correct
31 Correct 66 ms 31864 KB Output is correct
32 Correct 44 ms 31864 KB Output is correct
33 Correct 63 ms 31864 KB Output is correct
34 Correct 79 ms 31556 KB Output is correct
35 Correct 50 ms 28920 KB Output is correct
36 Correct 60 ms 29944 KB Output is correct
37 Correct 86 ms 30456 KB Output is correct
38 Correct 45 ms 29420 KB Output is correct
39 Correct 78 ms 29048 KB Output is correct
40 Correct 44 ms 29432 KB Output is correct
41 Correct 67 ms 31096 KB Output is correct
42 Correct 76 ms 31800 KB Output is correct
43 Correct 74 ms 30484 KB Output is correct
44 Correct 77 ms 28948 KB Output is correct
45 Correct 50 ms 29688 KB Output is correct
46 Correct 70 ms 29260 KB Output is correct
47 Correct 72 ms 29816 KB Output is correct
48 Correct 60 ms 29404 KB Output is correct
49 Correct 40 ms 29436 KB Output is correct
50 Correct 79 ms 31096 KB Output is correct
51 Correct 57 ms 30100 KB Output is correct
52 Correct 60 ms 30968 KB Output is correct
53 Correct 88 ms 31864 KB Output is correct
54 Correct 55 ms 31864 KB Output is correct
55 Correct 79 ms 31864 KB Output is correct
56 Correct 85 ms 31992 KB Output is correct
57 Correct 47 ms 31920 KB Output is correct
58 Correct 87 ms 31864 KB Output is correct