# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
611701 |
2022-07-29T06:43:45 Z |
이동현(#8500) |
Ljetopica (COI19_ljetopica) |
C++17 |
|
87 ms |
63548 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = (int)1e9 + 7;
int n, k;
string s;
int dp[1004][1004][2][2];
int cnt[1004][1004][2][2];
int sol(string f, int mst){
f = f.substr(1);
memset(dp, 0, sizeof(dp));
memset(cnt, 0, sizeof(cnt));
dp[0][0][0][0] = dp[0][0][1][0] = cnt[0][0][0][0] = cnt[0][0][1][0] = 1;
for(int i = 0; i < n; ++i){
for(int j = 0; j <= k; ++j){
for(int x = 0; x < 2; ++x){
for(int y = 0; y < 2; ++y){
if(!cnt[i][j][x][y] && !dp[i][j][x][y]) continue;
int num = ((s[i] == 'R') ^ x);
if(!num){
cnt[i + 1][j][x][y | (num < f[i] - '0')] = (cnt[i + 1][j][x][y | (num < f[i] - '0')] + (cnt[i][j][x][y])) % mod;
if((y || f[i] - '0' == 1) && j + 1 <= k){
cnt[i + 1][j + 1][x ^ 1][y] = (cnt[i + 1][j + 1][x ^ 1][y] + (cnt[i][j][x][y])) % mod;
}
}
else{
if(y || f[i] - '0' == 1){
cnt[i + 1][j][x][y] = (cnt[i + 1][j][x][y] + cnt[i][j][x][y]) % mod;
}
if(j + 1 <= k){
cnt[i + 1][j + 1][x ^ 1][y | (0 < f[i] - '0')] = (cnt[i + 1][j + 1][x ^ 1][y | (0 < f[i] - '0')] + cnt[i][j][x][y]) % mod;
}
}
if(!num){
dp[i + 1][j][x][y | (num < f[i] - '0')] = (dp[i + 1][j][x][y | (num < f[i] - '0')] + (dp[i][j][x][y] << 1)) % mod;
if((y || f[i] - '0' == 1) && j + 1 <= k){
dp[i + 1][j + 1][x ^ 1][y] = (dp[i + 1][j + 1][x ^ 1][y] + ((dp[i][j][x][y] << 1) + cnt[i][j][x][y])) % mod;
}
}
else{
if(y || f[i] - '0' == 1){
dp[i + 1][j][x][y] = (dp[i + 1][j][x][y] + ((dp[i][j][x][y] << 1) + cnt[i][j][x][y])) % mod;
}
if(j + 1 <= k){
dp[i + 1][j + 1][x ^ 1][y | (0 < f[i] - '0')] = (dp[i + 1][j + 1][x ^ 1][y | (0 < f[i] - '0')] + (dp[i][j][x][y] << 1)) % mod;
}
}
}
}
}
}
if(mst){
return (dp[n][k][0][1] + dp[n][k][1][1]) % mod;
}
return (dp[n][k][0][1] + dp[n][k][1][1] + dp[n][k][0][0] + dp[n][k][1][0]) % mod;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k; --n;
cin >> s;
string a, b; cin >> a >> b;
cout << (sol(b, 0) - sol(a, 1) + mod) % mod;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
63344 KB |
Output is correct |
2 |
Correct |
33 ms |
63368 KB |
Output is correct |
3 |
Correct |
37 ms |
63348 KB |
Output is correct |
4 |
Correct |
32 ms |
63332 KB |
Output is correct |
5 |
Correct |
34 ms |
63420 KB |
Output is correct |
6 |
Correct |
31 ms |
63332 KB |
Output is correct |
7 |
Correct |
31 ms |
63444 KB |
Output is correct |
8 |
Correct |
33 ms |
63416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
63484 KB |
Output is correct |
2 |
Correct |
32 ms |
63436 KB |
Output is correct |
3 |
Correct |
33 ms |
63308 KB |
Output is correct |
4 |
Correct |
35 ms |
63312 KB |
Output is correct |
5 |
Correct |
42 ms |
63424 KB |
Output is correct |
6 |
Correct |
40 ms |
63328 KB |
Output is correct |
7 |
Correct |
39 ms |
63316 KB |
Output is correct |
8 |
Correct |
39 ms |
63320 KB |
Output is correct |
9 |
Correct |
36 ms |
63308 KB |
Output is correct |
10 |
Correct |
32 ms |
63416 KB |
Output is correct |
11 |
Correct |
34 ms |
63444 KB |
Output is correct |
12 |
Correct |
42 ms |
63420 KB |
Output is correct |
13 |
Correct |
39 ms |
63396 KB |
Output is correct |
14 |
Correct |
34 ms |
63304 KB |
Output is correct |
15 |
Correct |
34 ms |
63316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
63468 KB |
Output is correct |
2 |
Correct |
54 ms |
63424 KB |
Output is correct |
3 |
Correct |
58 ms |
63428 KB |
Output is correct |
4 |
Correct |
87 ms |
63432 KB |
Output is correct |
5 |
Correct |
50 ms |
63324 KB |
Output is correct |
6 |
Correct |
76 ms |
63428 KB |
Output is correct |
7 |
Correct |
42 ms |
63372 KB |
Output is correct |
8 |
Correct |
52 ms |
63492 KB |
Output is correct |
9 |
Correct |
40 ms |
63424 KB |
Output is correct |
10 |
Correct |
49 ms |
63424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
63344 KB |
Output is correct |
2 |
Correct |
33 ms |
63368 KB |
Output is correct |
3 |
Correct |
37 ms |
63348 KB |
Output is correct |
4 |
Correct |
32 ms |
63332 KB |
Output is correct |
5 |
Correct |
34 ms |
63420 KB |
Output is correct |
6 |
Correct |
31 ms |
63332 KB |
Output is correct |
7 |
Correct |
31 ms |
63444 KB |
Output is correct |
8 |
Correct |
33 ms |
63416 KB |
Output is correct |
9 |
Correct |
33 ms |
63484 KB |
Output is correct |
10 |
Correct |
32 ms |
63436 KB |
Output is correct |
11 |
Correct |
33 ms |
63308 KB |
Output is correct |
12 |
Correct |
35 ms |
63312 KB |
Output is correct |
13 |
Correct |
42 ms |
63424 KB |
Output is correct |
14 |
Correct |
40 ms |
63328 KB |
Output is correct |
15 |
Correct |
39 ms |
63316 KB |
Output is correct |
16 |
Correct |
39 ms |
63320 KB |
Output is correct |
17 |
Correct |
36 ms |
63308 KB |
Output is correct |
18 |
Correct |
32 ms |
63416 KB |
Output is correct |
19 |
Correct |
34 ms |
63444 KB |
Output is correct |
20 |
Correct |
42 ms |
63420 KB |
Output is correct |
21 |
Correct |
39 ms |
63396 KB |
Output is correct |
22 |
Correct |
34 ms |
63304 KB |
Output is correct |
23 |
Correct |
34 ms |
63316 KB |
Output is correct |
24 |
Correct |
56 ms |
63468 KB |
Output is correct |
25 |
Correct |
54 ms |
63424 KB |
Output is correct |
26 |
Correct |
58 ms |
63428 KB |
Output is correct |
27 |
Correct |
87 ms |
63432 KB |
Output is correct |
28 |
Correct |
50 ms |
63324 KB |
Output is correct |
29 |
Correct |
76 ms |
63428 KB |
Output is correct |
30 |
Correct |
42 ms |
63372 KB |
Output is correct |
31 |
Correct |
52 ms |
63492 KB |
Output is correct |
32 |
Correct |
40 ms |
63424 KB |
Output is correct |
33 |
Correct |
49 ms |
63424 KB |
Output is correct |
34 |
Correct |
71 ms |
63424 KB |
Output is correct |
35 |
Correct |
49 ms |
63380 KB |
Output is correct |
36 |
Correct |
60 ms |
63428 KB |
Output is correct |
37 |
Correct |
83 ms |
63548 KB |
Output is correct |
38 |
Correct |
44 ms |
63444 KB |
Output is correct |
39 |
Correct |
70 ms |
63444 KB |
Output is correct |
40 |
Correct |
39 ms |
63444 KB |
Output is correct |
41 |
Correct |
63 ms |
63428 KB |
Output is correct |
42 |
Correct |
70 ms |
63428 KB |
Output is correct |
43 |
Correct |
77 ms |
63424 KB |
Output is correct |
44 |
Correct |
74 ms |
63424 KB |
Output is correct |
45 |
Correct |
53 ms |
63324 KB |
Output is correct |
46 |
Correct |
65 ms |
63404 KB |
Output is correct |
47 |
Correct |
71 ms |
63352 KB |
Output is correct |
48 |
Correct |
53 ms |
63316 KB |
Output is correct |
49 |
Correct |
34 ms |
63404 KB |
Output is correct |
50 |
Correct |
72 ms |
63428 KB |
Output is correct |
51 |
Correct |
53 ms |
63312 KB |
Output is correct |
52 |
Correct |
55 ms |
63440 KB |
Output is correct |
53 |
Correct |
82 ms |
63428 KB |
Output is correct |
54 |
Correct |
50 ms |
63428 KB |
Output is correct |
55 |
Correct |
70 ms |
63432 KB |
Output is correct |
56 |
Correct |
84 ms |
63432 KB |
Output is correct |
57 |
Correct |
44 ms |
63424 KB |
Output is correct |
58 |
Correct |
78 ms |
63308 KB |
Output is correct |