답안 #558617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558617 2022-05-07T15:49:02 Z Yazan_Alattar Ljetopica (COI19_ljetopica) C++14
100 / 100
151 ms 69812 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 3007;
const ll inf = 2e9;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-6;
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;

ll n, k, dp[M][M][2][2], dp2[M][M][2][2];
string s, a, b;

ll solve(string x){
    for(int i = 0; i <= n; ++i) for(int j = 0; j <= k; ++j) for(int Smaller : {0, 1}) for(int flip : {0, 1}) dp[i][j][Smaller][flip] = dp2[i][j][Smaller][flip] = 0;

    dp[0][0][x[0] == '0'][0] = dp[0][0][x[0] == '0'][1] = 1;
    dp2[0][0][x[0] == '0'][0] = dp2[0][0][x[0] == '0'][1] = 1;

    for(int i = 0; i < n - 1; ++i){
        for(int j = 0; j <= k; ++j){
            for(int flip : {0, 1}){
                ll on = (s[i + 1] - '0') ^ flip;
                bool isSmaller1 = (x[i + 1] == '1' && on == 0);
                bool isSmaller2 = (x[i + 1] == '1' && on);

                dp[i + 1][j][1][flip] = (dp[i + 1][j][1][flip] + dp[i][j][1][flip]) % mod;
                dp[i + 1][j + 1][1][!flip] = (dp[i + 1][j + 1][1][!flip] + dp[i][j][1][flip]) % mod;

                dp2[i + 1][j][1][flip] = (dp2[i + 1][j][1][flip] + 2 * dp2[i][j][1][flip] + dp[i][j][1][flip] * on) % mod;
                dp2[i + 1][j + 1][1][!flip] = (dp2[i + 1][j + 1][1][!flip] + 2 * dp2[i][j][1][flip] + dp[i][j][1][flip] * !on) % mod;


                if(x[i + 1] == '1' || !on) dp[i + 1][j][isSmaller1][flip] = (dp[i + 1][j][isSmaller1][flip] + dp[i][j][0][flip]) % mod;
                if(x[i + 1] == '1' || on) dp[i + 1][j + 1][isSmaller2][!flip] = (dp[i + 1][j + 1][isSmaller2][!flip] + dp[i][j][0][flip]) % mod;

                if(x[i + 1] == '1' || !on) dp2[i + 1][j][isSmaller1][flip] = (dp2[i + 1][j][isSmaller1][flip] + 2 * dp2[i][j][0][flip] + dp[i][j][0][flip] * on) % mod;
                if(x[i + 1] == '1' || on) dp2[i + 1][j + 1][isSmaller2][!flip] = (dp2[i + 1][j + 1][isSmaller2][!flip] + 2 * dp2[i][j][0][flip] + dp[i][j][0][flip] * !on) % mod;
            }
        }
    }

    ll ret = 0;
    for(int i : {0, 1})
        for(int j : {0, 1})
            ret = (ret + dp2[n - 1][k][i][j]) % mod;

    return ret;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k >> s >> a >> b;
    s = '#' + s;
    for(int i = 1; i < n; ++i){
        if(s[i] == 'L') s[i] = '0';
        else s[i] = '1';
    }

    for(int i = n - 1; i >= 0; --i){
        if(a[i] == '0') a[i] = '1';
        else{
            a[i] = '0';
            break;
        }
    }

    cout << (solve(b) - solve(a) + mod) % mod;
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8660 KB Output is correct
2 Correct 6 ms 8260 KB Output is correct
3 Correct 4 ms 7928 KB Output is correct
4 Correct 4 ms 7508 KB Output is correct
5 Correct 3 ms 6996 KB Output is correct
6 Correct 3 ms 6728 KB Output is correct
7 Correct 3 ms 6228 KB Output is correct
8 Correct 3 ms 5716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 456 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 456 KB Output is correct
13 Correct 1 ms 580 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 44608 KB Output is correct
2 Correct 65 ms 33500 KB Output is correct
3 Correct 74 ms 37044 KB Output is correct
4 Correct 146 ms 67320 KB Output is correct
5 Correct 58 ms 32016 KB Output is correct
6 Correct 151 ms 69812 KB Output is correct
7 Correct 41 ms 22868 KB Output is correct
8 Correct 75 ms 36684 KB Output is correct
9 Correct 7 ms 9812 KB Output is correct
10 Correct 64 ms 33908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8660 KB Output is correct
2 Correct 6 ms 8260 KB Output is correct
3 Correct 4 ms 7928 KB Output is correct
4 Correct 4 ms 7508 KB Output is correct
5 Correct 3 ms 6996 KB Output is correct
6 Correct 3 ms 6728 KB Output is correct
7 Correct 3 ms 6228 KB Output is correct
8 Correct 3 ms 5716 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 456 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 456 KB Output is correct
21 Correct 1 ms 580 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 84 ms 44608 KB Output is correct
25 Correct 65 ms 33500 KB Output is correct
26 Correct 74 ms 37044 KB Output is correct
27 Correct 146 ms 67320 KB Output is correct
28 Correct 58 ms 32016 KB Output is correct
29 Correct 151 ms 69812 KB Output is correct
30 Correct 41 ms 22868 KB Output is correct
31 Correct 75 ms 36684 KB Output is correct
32 Correct 7 ms 9812 KB Output is correct
33 Correct 64 ms 33908 KB Output is correct
34 Correct 103 ms 52904 KB Output is correct
35 Correct 44 ms 23252 KB Output is correct
36 Correct 70 ms 33276 KB Output is correct
37 Correct 142 ms 64936 KB Output is correct
38 Correct 22 ms 15104 KB Output is correct
39 Correct 117 ms 57324 KB Output is correct
40 Correct 20 ms 14036 KB Output is correct
41 Correct 90 ms 40760 KB Output is correct
42 Correct 103 ms 50160 KB Output is correct
43 Correct 101 ms 49876 KB Output is correct
44 Correct 126 ms 57016 KB Output is correct
45 Correct 41 ms 21908 KB Output is correct
46 Correct 99 ms 46308 KB Output is correct
47 Correct 96 ms 48616 KB Output is correct
48 Correct 60 ms 31136 KB Output is correct
49 Correct 8 ms 9428 KB Output is correct
50 Correct 114 ms 55220 KB Output is correct
51 Correct 56 ms 29108 KB Output is correct
52 Correct 59 ms 30948 KB Output is correct
53 Correct 140 ms 65780 KB Output is correct
54 Correct 39 ms 23736 KB Output is correct
55 Correct 107 ms 53980 KB Output is correct
56 Correct 127 ms 60512 KB Output is correct
57 Correct 18 ms 13780 KB Output is correct
58 Correct 102 ms 48816 KB Output is correct