#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 aint(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;
string s, a, b;
ll n, k;
ll check(string s){
ll res = 1;
int mn = 1, mx = 1;
for(int i = 0; i < n - 1; ++i){
if(s[i] == 'L'){
// bit = 0
res = (res * 2) % mod;
if(mx == 1 && a[i + 1] == '1') mx = 0;
if(mn == 1 && b[i + 1] == '1') mn = 2;
}
else{
// bit = 1
res = (res * 2 + 1) % mod;
if(mx == 1 && a[i + 1] == '0') mx = 2;
if(mn == 1 && b[i + 1] == '0') mn = 0;
}
}
if(mn && mx) return res;
return 0ll;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
string S;
cin >> n >> k >> S >> a >> b;
ll ans = check(S);
for(int i = 0; i < n - 1; ++i){
if(S[i] == 'L') S[i] = 'R';
else S[i] = 'L';
}
ans += check(S);
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |