Submission #467579

# Submission time Handle Problem Language Result Execution time Memory
467579 2021-08-23T18:10:17 Z couplefire Ljetopica (COI19_ljetopica) C++17
100 / 100
215 ms 63236 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1005;
const int MOD = 1000000007;

inline int add(int a, int b){return (a+b>=MOD)?a+b-MOD:a+b;}
inline void inc(int& a, int b){a = add(a, b);}
inline int sub(int a, int b){return (a-b<0)?a-b+MOD:a-b;}
inline void dec(int &a, int b){a = sub(a, b);}
inline int mul(int a, int b){return 1ll*a*b%MOD;}
inline void grow(int &a, int b){a = mul(a, b);}

int n, k, dp1[N][N][2][2][2], dp2[N][N][2][2][2], ans;
int moves[N], lo[N], hi[N]; string _str;

int main(){
    // freopen("a.in", "r", stdin);
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> k >> _str;
    for(int i = 0; i<n-1; ++i)
        moves[i] = _str[i]=='L'?0:1;
    cin >> _str;
    for(int i = 0; i<n; ++i)
        lo[i] = _str[i]-'0';
    cin >> _str;
    for(int i = 0; i<n; ++i)
        hi[i] = _str[i]-'0';
    dp1[0][0][1][1][0] = dp1[0][0][1][1][1] = dp2[0][0][1][1][0] = dp2[0][0][1][1][1] = 1;
    for(int pos = 0; pos<n-1; ++pos)
        for(int take = 0; take<=k; ++take)
            for(int smol = 0; smol<2; ++smol)
                for(int fat = 0; fat<2; ++fat)
                    for(int flag = 0; flag<2; ++flag){
                        int nxt = moves[pos]^flag;
                        int v1 = dp1[pos][take][smol][fat][flag];
                        int v2 = dp2[pos][take][smol][fat][flag];
                        // do nothing
                        if((!smol || (nxt>=lo[pos+1])) && (!fat || (nxt<=hi[pos+1])))
                            inc(dp1[pos+1][take][smol && nxt==lo[pos+1]][fat && nxt==hi[pos+1]][flag], add(mul(v1, 2), mul(nxt==1, v2))),
                            inc(dp2[pos+1][take][smol && nxt==lo[pos+1]][fat && nxt==hi[pos+1]][flag], v2);
                        
                        // flip it
                        if(take==k) continue;
                        nxt ^= 1;
                        if((!smol || (nxt>=lo[pos+1])) && (!fat || (nxt<=hi[pos+1])))
                            inc(dp1[pos+1][take+1][smol && nxt==lo[pos+1]][fat && nxt==hi[pos+1]][flag^1], add(mul(v1, 2), mul(nxt==1, v2))),
                            inc(dp2[pos+1][take+1][smol && nxt==lo[pos+1]][fat && nxt==hi[pos+1]][flag^1], v2);
                    }
    for(int a = 0; a<2; ++a)
        for(int b = 0; b<2; ++b)
            for(int c = 0; c<2; ++c)
                inc(ans, dp1[n-1][k][a][b][c]);
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8396 KB Output is correct
2 Correct 5 ms 8004 KB Output is correct
3 Correct 5 ms 7628 KB Output is correct
4 Correct 4 ms 7244 KB Output is correct
5 Correct 4 ms 6812 KB Output is correct
6 Correct 5 ms 6348 KB Output is correct
7 Correct 4 ms 5964 KB Output is correct
8 Correct 4 ms 5608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 448 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 452 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 44156 KB Output is correct
2 Correct 96 ms 33084 KB Output is correct
3 Correct 114 ms 36612 KB Output is correct
4 Correct 191 ms 63136 KB Output is correct
5 Correct 90 ms 31660 KB Output is correct
6 Correct 215 ms 63120 KB Output is correct
7 Correct 54 ms 22508 KB Output is correct
8 Correct 109 ms 36232 KB Output is correct
9 Correct 9 ms 9548 KB Output is correct
10 Correct 99 ms 33560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8396 KB Output is correct
2 Correct 5 ms 8004 KB Output is correct
3 Correct 5 ms 7628 KB Output is correct
4 Correct 4 ms 7244 KB Output is correct
5 Correct 4 ms 6812 KB Output is correct
6 Correct 5 ms 6348 KB Output is correct
7 Correct 4 ms 5964 KB Output is correct
8 Correct 4 ms 5608 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 448 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 452 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 169 ms 44156 KB Output is correct
25 Correct 96 ms 33084 KB Output is correct
26 Correct 114 ms 36612 KB Output is correct
27 Correct 191 ms 63136 KB Output is correct
28 Correct 90 ms 31660 KB Output is correct
29 Correct 215 ms 63120 KB Output is correct
30 Correct 54 ms 22508 KB Output is correct
31 Correct 109 ms 36232 KB Output is correct
32 Correct 9 ms 9548 KB Output is correct
33 Correct 99 ms 33560 KB Output is correct
34 Correct 153 ms 52476 KB Output is correct
35 Correct 86 ms 22888 KB Output is correct
36 Correct 82 ms 32836 KB Output is correct
37 Correct 176 ms 60052 KB Output is correct
38 Correct 26 ms 14788 KB Output is correct
39 Correct 156 ms 56920 KB Output is correct
40 Correct 23 ms 13684 KB Output is correct
41 Correct 114 ms 40308 KB Output is correct
42 Correct 145 ms 49676 KB Output is correct
43 Correct 133 ms 49428 KB Output is correct
44 Correct 154 ms 56644 KB Output is correct
45 Correct 52 ms 21524 KB Output is correct
46 Correct 123 ms 45784 KB Output is correct
47 Correct 129 ms 48188 KB Output is correct
48 Correct 76 ms 30776 KB Output is correct
49 Correct 10 ms 9164 KB Output is correct
50 Correct 149 ms 54788 KB Output is correct
51 Correct 69 ms 28748 KB Output is correct
52 Correct 76 ms 30444 KB Output is correct
53 Correct 182 ms 63236 KB Output is correct
54 Correct 51 ms 23232 KB Output is correct
55 Correct 161 ms 53572 KB Output is correct
56 Correct 186 ms 60040 KB Output is correct
57 Correct 21 ms 13508 KB Output is correct
58 Correct 131 ms 48452 KB Output is correct