답안 #129845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
129845 2019-07-13T10:37:44 Z pzdba Ljetopica (COI19_ljetopica) C++14
100 / 100
116 ms 63352 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
char s[1002], a[1002], b[1002];
ll dp[1002][1002][2][2], cnt[1002][1002][2][2];
int n, k;

int dfs(char *t){
    if(t[1] == '0') return 0;

    memset(dp, 0, sizeof(dp));
    memset(cnt, 0, sizeof(cnt));

    dp[1][0][1][0] = 1;
    cnt[1][0][1][0] = 1;

    dp[1][0][1][1] = 1;
    cnt[1][0][1][1] = 1;

    bool ok = 0;

    for(int i=2;i<=n;i++){
        for(int j=0;j<=k;j++){
            if(s[i] == 'L'){
                dp[i][j][0][0] = (dp[i][j][0][0] + dp[i-1][j][0][0]*2)%mod;
                cnt[i][j][0][0] = (cnt[i][j][0][0] + cnt[i-1][j][0][0])%mod;

                dp[i][j][0][1] = (dp[i][j][0][1] + dp[i-1][j][0][1]*2 + cnt[i-1][j][0][1])%mod;
                cnt[i][j][0][1] = (cnt[i][j][0][1] + cnt[i-1][j][0][1])%mod;


                if(t[i] == '1'){
                    dp[i][j][1][1] = (dp[i][j][1][1] + dp[i-1][j][1][1]*2 + cnt[i-1][j][1][1])%mod;
                    cnt[i][j][1][1] = (cnt[i][j][1][1] + cnt[i-1][j][1][1])%mod;

                    dp[i][j][0][0] = (dp[i][j][0][0] + dp[i-1][j][1][0]*2)%mod;
                    cnt[i][j][0][0] = (cnt[i][j][0][0] + cnt[i-1][j][1][0])%mod;
                }
                else{
                    dp[i][j][1][0] = (dp[i][j][1][0] + dp[i-1][j][1][0]*2)%mod;
                    cnt[i][j][1][0] = (cnt[i][j][1][0] + cnt[i-1][j][1][0])%mod;
                }


                if(j != k){
                    dp[i][j+1][0][1] = (dp[i][j+1][0][1] + dp[i-1][j][0][0]*2 + cnt[i-1][j][0][0])%mod;
                    cnt[i][j+1][0][1] = (cnt[i][j+1][0][1] + cnt[i-1][j][0][0])%mod;

                    dp[i][j+1][0][0] = (dp[i][j+1][0][0] + dp[i-1][j][0][1]*2)%mod;
                    cnt[i][j+1][0][0] = (cnt[i][j+1][0][0] + cnt[i-1][j][0][1])%mod;

                    if(t[i] == '1'){
                        dp[i][j+1][1][1] = (dp[i][j+1][1][1] + dp[i-1][j][1][0]*2 + cnt[i-1][j][1][0])%mod;
                        cnt[i][j+1][1][1] = (cnt[i][j+1][1][1] + cnt[i-1][j][1][0])%mod;

                        dp[i][j+1][0][0] = (dp[i][j+1][0][0] + dp[i-1][j][1][1]*2)%mod;
                        cnt[i][j+1][0][0] = (cnt[i][j+1][0][0] + cnt[i-1][j][1][1])%mod;
                    }
                    else{
                        dp[i][j+1][1][0] = (dp[i][j+1][1][0] + dp[i-1][j][1][1]*2)%mod;
                        cnt[i][j+1][1][0] = (cnt[i][j+1][1][0] + cnt[i-1][j][1][1])%mod;
                    }

                }
            }
            else{
                dp[i][j][0][0] = (dp[i][j][0][0] + dp[i-1][j][0][0]*2 + cnt[i-1][j][0][0])%mod;
                cnt[i][j][0][0] = (cnt[i][j][0][0] + cnt[i-1][j][0][0])%mod;

                dp[i][j][0][1] = (dp[i][j][0][1] + dp[i-1][j][0][1]*2)%mod;
                cnt[i][j][0][1] = (cnt[i][j][0][1] + cnt[i-1][j][0][1])%mod;


                if(t[i] == '1'){
                    dp[i][j][1][0] = (dp[i][j][1][0] + dp[i-1][j][1][0]*2 + cnt[i-1][j][1][0])%mod;
                    cnt[i][j][1][0] = (cnt[i][j][1][0] + cnt[i-1][j][1][0])%mod;

                    dp[i][j][0][1] = (dp[i][j][0][1] + dp[i-1][j][1][1]*2)%mod;
                    cnt[i][j][0][1] = (cnt[i][j][0][1] + cnt[i-1][j][1][1])%mod;
                }
                else{
                    dp[i][j][1][1] = (dp[i][j][1][1] + dp[i-1][j][1][1]*2)%mod;
                    cnt[i][j][1][1] = (cnt[i][j][1][1] + cnt[i-1][j][1][1])%mod;
                }


                if(j != k){
                    dp[i][j+1][0][1] = (dp[i][j+1][0][1] + dp[i-1][j][0][0]*2)%mod;
                    cnt[i][j+1][0][1] = (cnt[i][j+1][0][1] + cnt[i-1][j][0][0])%mod;

                    dp[i][j+1][0][0] = (dp[i][j+1][0][0] + dp[i-1][j][0][1]*2 + cnt[i-1][j][0][1])%mod;
                    cnt[i][j+1][0][0] = (cnt[i][j+1][0][0] + cnt[i-1][j][0][1])%mod;


                    if(t[i] == '1'){
                        dp[i][j+1][1][0] = (dp[i][j+1][1][0] + dp[i-1][j][1][1]*2 + cnt[i-1][j][1][1])%mod;
                        cnt[i][j+1][1][0] = (cnt[i][j+1][1][0] + cnt[i-1][j][1][1])%mod;

                        dp[i][j+1][0][1] = (dp[i][j+1][0][1] + dp[i-1][j][1][0]*2)%mod;
                        cnt[i][j+1][0][1] = (cnt[i][j+1][0][1] + cnt[i-1][j][1][0])%mod;
                    }
                    else{
                        dp[i][j+1][1][1] = (dp[i][j+1][1][1] + dp[i-1][j][1][0]*2)%mod;
                        cnt[i][j+1][1][1] = (cnt[i][j+1][1][1] + cnt[i-1][j][1][0])%mod;
                    }
                }
            }
        }
    }
    return (dp[n][k][0][0] + dp[n][k][0][1] + dp[n][k][1][0] + dp[n][k][1][1])%mod;
}

int main(){
    scanf("%d%d", &n, &k);
    scanf("%s", s+2);    
    scanf("%s", a+1);
    scanf("%s", b+1);

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

    int res1 = dfs(b);
    int res2 = dfs(a);

    printf("%d\n", (res1 - res2 + mod)%mod);
}

Compilation message

ljetopica.cpp: In function 'int dfs(char*)':
ljetopica.cpp:21:10: warning: unused variable 'ok' [-Wunused-variable]
     bool ok = 0;
          ^~
ljetopica.cpp: In function 'int main()':
ljetopica.cpp:115:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
ljetopica.cpp:116:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", s+2);    
     ~~~~~^~~~~~~~~~~
ljetopica.cpp:117:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", a+1);
     ~~~~~^~~~~~~~~~~
ljetopica.cpp:118:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", b+1);
     ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 63224 KB Output is correct
2 Correct 65 ms 63228 KB Output is correct
3 Correct 65 ms 63192 KB Output is correct
4 Correct 65 ms 63224 KB Output is correct
5 Correct 66 ms 63224 KB Output is correct
6 Correct 65 ms 63224 KB Output is correct
7 Correct 65 ms 63352 KB Output is correct
8 Correct 65 ms 63320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 63224 KB Output is correct
2 Correct 65 ms 63224 KB Output is correct
3 Correct 65 ms 63184 KB Output is correct
4 Correct 65 ms 63224 KB Output is correct
5 Correct 65 ms 63228 KB Output is correct
6 Correct 65 ms 63224 KB Output is correct
7 Correct 65 ms 63264 KB Output is correct
8 Correct 65 ms 63224 KB Output is correct
9 Correct 65 ms 63224 KB Output is correct
10 Correct 81 ms 63180 KB Output is correct
11 Correct 81 ms 63224 KB Output is correct
12 Correct 73 ms 63224 KB Output is correct
13 Correct 80 ms 63224 KB Output is correct
14 Correct 82 ms 63352 KB Output is correct
15 Correct 66 ms 63228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 63268 KB Output is correct
2 Correct 86 ms 63232 KB Output is correct
3 Correct 89 ms 63248 KB Output is correct
4 Correct 114 ms 63224 KB Output is correct
5 Correct 85 ms 63224 KB Output is correct
6 Correct 116 ms 63224 KB Output is correct
7 Correct 77 ms 63224 KB Output is correct
8 Correct 89 ms 63228 KB Output is correct
9 Correct 67 ms 63352 KB Output is correct
10 Correct 86 ms 63224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 63224 KB Output is correct
2 Correct 65 ms 63228 KB Output is correct
3 Correct 65 ms 63192 KB Output is correct
4 Correct 65 ms 63224 KB Output is correct
5 Correct 66 ms 63224 KB Output is correct
6 Correct 65 ms 63224 KB Output is correct
7 Correct 65 ms 63352 KB Output is correct
8 Correct 65 ms 63320 KB Output is correct
9 Correct 64 ms 63224 KB Output is correct
10 Correct 65 ms 63224 KB Output is correct
11 Correct 65 ms 63184 KB Output is correct
12 Correct 65 ms 63224 KB Output is correct
13 Correct 65 ms 63228 KB Output is correct
14 Correct 65 ms 63224 KB Output is correct
15 Correct 65 ms 63264 KB Output is correct
16 Correct 65 ms 63224 KB Output is correct
17 Correct 65 ms 63224 KB Output is correct
18 Correct 81 ms 63180 KB Output is correct
19 Correct 81 ms 63224 KB Output is correct
20 Correct 73 ms 63224 KB Output is correct
21 Correct 80 ms 63224 KB Output is correct
22 Correct 82 ms 63352 KB Output is correct
23 Correct 66 ms 63228 KB Output is correct
24 Correct 96 ms 63268 KB Output is correct
25 Correct 86 ms 63232 KB Output is correct
26 Correct 89 ms 63248 KB Output is correct
27 Correct 114 ms 63224 KB Output is correct
28 Correct 85 ms 63224 KB Output is correct
29 Correct 116 ms 63224 KB Output is correct
30 Correct 77 ms 63224 KB Output is correct
31 Correct 89 ms 63228 KB Output is correct
32 Correct 67 ms 63352 KB Output is correct
33 Correct 86 ms 63224 KB Output is correct
34 Correct 102 ms 63196 KB Output is correct
35 Correct 96 ms 63224 KB Output is correct
36 Correct 86 ms 63204 KB Output is correct
37 Correct 113 ms 63224 KB Output is correct
38 Correct 73 ms 63324 KB Output is correct
39 Correct 106 ms 63224 KB Output is correct
40 Correct 70 ms 63224 KB Output is correct
41 Correct 91 ms 63224 KB Output is correct
42 Correct 99 ms 63248 KB Output is correct
43 Correct 100 ms 63224 KB Output is correct
44 Correct 106 ms 63224 KB Output is correct
45 Correct 77 ms 63224 KB Output is correct
46 Correct 97 ms 63224 KB Output is correct
47 Correct 99 ms 63224 KB Output is correct
48 Correct 84 ms 63224 KB Output is correct
49 Correct 67 ms 63224 KB Output is correct
50 Correct 114 ms 63240 KB Output is correct
51 Correct 102 ms 63224 KB Output is correct
52 Correct 109 ms 63224 KB Output is correct
53 Correct 113 ms 63224 KB Output is correct
54 Correct 78 ms 63148 KB Output is correct
55 Correct 105 ms 63224 KB Output is correct
56 Correct 109 ms 63352 KB Output is correct
57 Correct 70 ms 63224 KB Output is correct
58 Correct 99 ms 63224 KB Output is correct