Submission #465714

# Submission time Handle Problem Language Result Execution time Memory
465714 2021-08-16T16:58:19 Z SirCovidThe19th Ljetopica (COI19_ljetopica) C++17
100 / 100
124 ms 16160 KB
#include <bits/stdc++.h>
using namespace std; 

#define FOR(i, x, y) for (int i = x; i < y; i++)
#define ad(x, y) x = ((x) + (y)) % md

const int mx = 1005, md = 1e9 + 7;

int n, k, mv[mx]; bitset<mx> A, B;

int solve(bitset<mx> X){
    bool cover[mx] = {}; int sum[mx][mx][2] = {}, cnt[mx][mx][2] = {};

    for (int i = n - 1; i >= 0, cover[i] = 1, X[n - i - 1]; i--);

    sum[0][0][!cover[0]] = cnt[0][0][!cover[0]] = 1;
    
    X <<= 1;
    FOR(i, 0, n - 1) FOR(j, 0, k + 1){
        int f = j % 2, L = !(mv[i] ^ f), R = 1 - L;

        ad(sum[i + 1][j + R][0], sum[i][j][0] * 2LL);
        ad(sum[i + 1][j + L][0], sum[i][j][0] * 2LL + cnt[i][j][0]);

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

        int tight = !X[n - i - 1] and !cover[i + 1];
        ad(sum[i + 1][j + R][tight], sum[i][j][1] * 2LL);
        ad(cnt[i + 1][j + R][tight], cnt[i][j][1]);

        if (X[n - i - 1]){
            ad(sum[i + 1][j + L][1], sum[i][j][1] * 2LL + cnt[i][j][1]);
            ad(cnt[i + 1][j + L][1], cnt[i][j][1]);
        }
    }
    return sum[n - 1][k][0];
}


int main(){
    cin >> n >> k;
    FOR(i, 0, n - 1){ char c; cin >> c; mv[i] = c == 'R'; }
    cin >> A >> B;
    for (int i = 0; i < n; i++){ 
        if (A[i]){ A[i] = 0; break; } 
        else A[i] = 1;
    }
    int res1 = solve(B); if (A[n - 1]) res1 -= solve(A);
    FOR(i, 0, n - 1) mv[i] ^= 1;
    int res2 = solve(B); if (A[n - 1]) res2 -= solve(A);
    cout<<((long long)res1 + res2 + 2 * md) % md<<endl;
}

Compilation message

ljetopica.cpp: In function 'int solve(std::bitset<1005>)':
ljetopica.cpp:14:27: warning: left operand of comma operator has no effect [-Wunused-value]
   14 |     for (int i = n - 1; i >= 0, cover[i] = 1, X[n - i - 1]; i--);
      |                         ~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 16076 KB Output is correct
2 Correct 17 ms 16112 KB Output is correct
3 Correct 19 ms 16112 KB Output is correct
4 Correct 16 ms 16076 KB Output is correct
5 Correct 16 ms 16076 KB Output is correct
6 Correct 17 ms 16108 KB Output is correct
7 Correct 16 ms 16104 KB Output is correct
8 Correct 17 ms 16104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 16012 KB Output is correct
2 Correct 17 ms 16088 KB Output is correct
3 Correct 16 ms 16128 KB Output is correct
4 Correct 16 ms 16112 KB Output is correct
5 Correct 17 ms 16104 KB Output is correct
6 Correct 16 ms 16076 KB Output is correct
7 Correct 16 ms 16108 KB Output is correct
8 Correct 16 ms 16076 KB Output is correct
9 Correct 17 ms 16076 KB Output is correct
10 Correct 15 ms 16076 KB Output is correct
11 Correct 16 ms 16032 KB Output is correct
12 Correct 18 ms 16112 KB Output is correct
13 Correct 18 ms 16076 KB Output is correct
14 Correct 15 ms 16112 KB Output is correct
15 Correct 15 ms 16076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 16084 KB Output is correct
2 Correct 44 ms 16084 KB Output is correct
3 Correct 50 ms 16084 KB Output is correct
4 Correct 79 ms 16084 KB Output is correct
5 Correct 44 ms 16076 KB Output is correct
6 Correct 104 ms 16084 KB Output is correct
7 Correct 35 ms 16076 KB Output is correct
8 Correct 46 ms 16076 KB Output is correct
9 Correct 18 ms 16108 KB Output is correct
10 Correct 50 ms 16076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 16076 KB Output is correct
2 Correct 17 ms 16112 KB Output is correct
3 Correct 19 ms 16112 KB Output is correct
4 Correct 16 ms 16076 KB Output is correct
5 Correct 16 ms 16076 KB Output is correct
6 Correct 17 ms 16108 KB Output is correct
7 Correct 16 ms 16104 KB Output is correct
8 Correct 17 ms 16104 KB Output is correct
9 Correct 17 ms 16012 KB Output is correct
10 Correct 17 ms 16088 KB Output is correct
11 Correct 16 ms 16128 KB Output is correct
12 Correct 16 ms 16112 KB Output is correct
13 Correct 17 ms 16104 KB Output is correct
14 Correct 16 ms 16076 KB Output is correct
15 Correct 16 ms 16108 KB Output is correct
16 Correct 16 ms 16076 KB Output is correct
17 Correct 17 ms 16076 KB Output is correct
18 Correct 15 ms 16076 KB Output is correct
19 Correct 16 ms 16032 KB Output is correct
20 Correct 18 ms 16112 KB Output is correct
21 Correct 18 ms 16076 KB Output is correct
22 Correct 15 ms 16112 KB Output is correct
23 Correct 15 ms 16076 KB Output is correct
24 Correct 62 ms 16084 KB Output is correct
25 Correct 44 ms 16084 KB Output is correct
26 Correct 50 ms 16084 KB Output is correct
27 Correct 79 ms 16084 KB Output is correct
28 Correct 44 ms 16076 KB Output is correct
29 Correct 104 ms 16084 KB Output is correct
30 Correct 35 ms 16076 KB Output is correct
31 Correct 46 ms 16076 KB Output is correct
32 Correct 18 ms 16108 KB Output is correct
33 Correct 50 ms 16076 KB Output is correct
34 Correct 76 ms 16040 KB Output is correct
35 Correct 33 ms 16076 KB Output is correct
36 Correct 47 ms 16076 KB Output is correct
37 Correct 88 ms 16084 KB Output is correct
38 Correct 29 ms 16092 KB Output is correct
39 Correct 82 ms 16068 KB Output is correct
40 Correct 23 ms 16104 KB Output is correct
41 Correct 52 ms 16088 KB Output is correct
42 Correct 74 ms 16088 KB Output is correct
43 Correct 65 ms 16076 KB Output is correct
44 Correct 71 ms 16076 KB Output is correct
45 Correct 38 ms 16096 KB Output is correct
46 Correct 57 ms 16084 KB Output is correct
47 Correct 72 ms 16084 KB Output is correct
48 Correct 44 ms 16076 KB Output is correct
49 Correct 19 ms 16112 KB Output is correct
50 Correct 68 ms 16088 KB Output is correct
51 Correct 41 ms 16076 KB Output is correct
52 Correct 41 ms 16076 KB Output is correct
53 Correct 78 ms 16076 KB Output is correct
54 Correct 33 ms 16020 KB Output is correct
55 Correct 124 ms 16160 KB Output is correct
56 Correct 74 ms 16048 KB Output is correct
57 Correct 22 ms 16104 KB Output is correct
58 Correct 89 ms 16076 KB Output is correct