This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |