답안 #465434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465434 2021-08-16T05:11:07 Z SirCovidThe19th Ljetopica (COI19_ljetopica) C++17
100 / 100
81 ms 16144 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][0], sum[i][j][0] * 2LL + (R ? cnt[i][j][0] : 0));
        ad(sum[i + 1][j + 1][0], sum[i][j][0] * 2LL + (L ? cnt[i][j][0] : 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] and !cover[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;
    }
    long long res1 = solve(B); if (A[n - 1]) res1 -= solve(A);
    FOR(i, 0, n - 1) mv[i] ^= 1;
    long long res2 = solve(B); if (A[n - 1]) res2 -= solve(A);
    cout<<(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--);
      |                         ~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 16076 KB Output is correct
2 Correct 15 ms 16076 KB Output is correct
3 Correct 15 ms 16108 KB Output is correct
4 Correct 16 ms 16076 KB Output is correct
5 Correct 16 ms 16076 KB Output is correct
6 Correct 15 ms 16104 KB Output is correct
7 Correct 15 ms 16012 KB Output is correct
8 Correct 15 ms 16076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 16076 KB Output is correct
2 Correct 15 ms 16068 KB Output is correct
3 Correct 15 ms 16144 KB Output is correct
4 Correct 15 ms 16108 KB Output is correct
5 Correct 15 ms 16108 KB Output is correct
6 Correct 15 ms 16076 KB Output is correct
7 Correct 15 ms 16076 KB Output is correct
8 Correct 15 ms 16108 KB Output is correct
9 Correct 15 ms 16076 KB Output is correct
10 Correct 17 ms 16076 KB Output is correct
11 Correct 15 ms 16076 KB Output is correct
12 Correct 15 ms 16104 KB Output is correct
13 Correct 15 ms 16108 KB Output is correct
14 Correct 16 ms 16112 KB Output is correct
15 Correct 16 ms 16108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 16088 KB Output is correct
2 Correct 42 ms 16076 KB Output is correct
3 Correct 46 ms 16076 KB Output is correct
4 Correct 79 ms 16088 KB Output is correct
5 Correct 42 ms 16088 KB Output is correct
6 Correct 81 ms 16076 KB Output is correct
7 Correct 30 ms 16076 KB Output is correct
8 Correct 45 ms 16040 KB Output is correct
9 Correct 17 ms 16104 KB Output is correct
10 Correct 41 ms 16076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 16076 KB Output is correct
2 Correct 15 ms 16076 KB Output is correct
3 Correct 15 ms 16108 KB Output is correct
4 Correct 16 ms 16076 KB Output is correct
5 Correct 16 ms 16076 KB Output is correct
6 Correct 15 ms 16104 KB Output is correct
7 Correct 15 ms 16012 KB Output is correct
8 Correct 15 ms 16076 KB Output is correct
9 Correct 16 ms 16076 KB Output is correct
10 Correct 15 ms 16068 KB Output is correct
11 Correct 15 ms 16144 KB Output is correct
12 Correct 15 ms 16108 KB Output is correct
13 Correct 15 ms 16108 KB Output is correct
14 Correct 15 ms 16076 KB Output is correct
15 Correct 15 ms 16076 KB Output is correct
16 Correct 15 ms 16108 KB Output is correct
17 Correct 15 ms 16076 KB Output is correct
18 Correct 17 ms 16076 KB Output is correct
19 Correct 15 ms 16076 KB Output is correct
20 Correct 15 ms 16104 KB Output is correct
21 Correct 15 ms 16108 KB Output is correct
22 Correct 16 ms 16112 KB Output is correct
23 Correct 16 ms 16108 KB Output is correct
24 Correct 54 ms 16088 KB Output is correct
25 Correct 42 ms 16076 KB Output is correct
26 Correct 46 ms 16076 KB Output is correct
27 Correct 79 ms 16088 KB Output is correct
28 Correct 42 ms 16088 KB Output is correct
29 Correct 81 ms 16076 KB Output is correct
30 Correct 30 ms 16076 KB Output is correct
31 Correct 45 ms 16040 KB Output is correct
32 Correct 17 ms 16104 KB Output is correct
33 Correct 41 ms 16076 KB Output is correct
34 Correct 61 ms 16044 KB Output is correct
35 Correct 31 ms 16076 KB Output is correct
36 Correct 42 ms 16032 KB Output is correct
37 Correct 73 ms 16080 KB Output is correct
38 Correct 24 ms 16076 KB Output is correct
39 Correct 67 ms 16036 KB Output is correct
40 Correct 23 ms 16112 KB Output is correct
41 Correct 48 ms 16044 KB Output is correct
42 Correct 58 ms 16076 KB Output is correct
43 Correct 58 ms 16076 KB Output is correct
44 Correct 67 ms 16048 KB Output is correct
45 Correct 30 ms 16076 KB Output is correct
46 Correct 56 ms 16076 KB Output is correct
47 Correct 57 ms 16084 KB Output is correct
48 Correct 40 ms 16076 KB Output is correct
49 Correct 19 ms 16112 KB Output is correct
50 Correct 65 ms 16076 KB Output is correct
51 Correct 37 ms 16104 KB Output is correct
52 Correct 38 ms 16076 KB Output is correct
53 Correct 80 ms 16076 KB Output is correct
54 Correct 31 ms 16076 KB Output is correct
55 Correct 62 ms 16036 KB Output is correct
56 Correct 70 ms 16040 KB Output is correct
57 Correct 20 ms 16076 KB Output is correct
58 Correct 57 ms 16076 KB Output is correct