Submission #558423

# Submission time Handle Problem Language Result Execution time Memory
558423 2022-05-07T09:46:28 Z Yazan_Alattar Ljetopica (COI19_ljetopica) C++14
17 / 100
9 ms 8532 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 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;

ll n, k, p[M], ans, c[M][M];
string s, a, b;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k >> s >> a >> b;
    s = '#' + s;

    p[0] = 1;
    for(int i = 1; i <= n; ++i) p[i] = (p[i - 1] * 2) % mod;

    for(int i = 0; i <= n; ++i){
        c[i][0] = 1;
        for(int j = 1; j <= i; ++j) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }

    ll ans = (p[n] * c[n - 1][k]) % mod;
    for(int i = 2; i <= n; ++i){
        for(int j = 0; j <= k; ++j){

            if(s[i - 1] == 'L' && j && j <= i - 1 && k - j <= n - i){
                ll add = (p[n - i] * c[n - i][k - j]) % mod;
                add = (add * c[i - 2][j - 1]) % mod;
                ans = (ans + add) % mod;
            }

            else if(s[i - 1] == 'R' && j <= i - 2 && k - j <= n - i){
                ll add = (p[n - i] * c[n - i][k - j]) % mod;
                add = (add * c[i - 2][j]) % mod;
                ans = (ans + add) % mod;
            }
        }
    }

    for(int i = 1; i < n; ++i){
        if(s[i] == 'L') s[i] = 'R';
        else s[i] = 'L';
    }

    for(int i = 2; i <= n; ++i){
        for(int j = 0; j <= k; ++j){

            if(s[i - 1] == 'L' && j && j <= i - 1 && k - j <= n - i){
                ll add = (p[n - i] * c[n - i][k - j]) % mod;
                add = (add * c[i - 2][j - 1]) % mod;
                ans = (ans + add) % mod;
            }

            else if(s[i - 1] == 'R' && j <= i - 2 && k - j <= n - i){
                ll add = (p[n - i] * c[n - i][k - j]) % mod;
                add = (add * c[i - 2][j]) % mod;
                ans = (ans + add) % mod;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 8404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8516 KB Output is correct
2 Correct 9 ms 8404 KB Output is correct
3 Correct 8 ms 8524 KB Output is correct
4 Correct 7 ms 8524 KB Output is correct
5 Correct 8 ms 8532 KB Output is correct
6 Correct 9 ms 8532 KB Output is correct
7 Correct 6 ms 8532 KB Output is correct
8 Correct 8 ms 8520 KB Output is correct
9 Correct 5 ms 8404 KB Output is correct
10 Correct 8 ms 8532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 8404 KB Output isn't correct
2 Halted 0 ms 0 KB -