Submission #894193

# Submission time Handle Problem Language Result Execution time Memory
894193 2023-12-28T02:41:47 Z noiaint Kangaroo (CEOI16_kangaroo) C++17
6 / 100
0 ms 348 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define getbit(x, i) (((x) >> (i)) & 1)
#define bit(x) (1 << (x))
#define file ""
using namespace std;

mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long r) {
    return l + rd() % (r - l + 1);
}

const int N = 2e3 + 5;
const int mod = 1e9 + 7; // 998244353;
const int inf = INT_MAX;
const long long llinf = LLONG_MAX;
const int lg = 25; // lg + 1

template<class X, class Y> bool minimize(X &a, Y b) {
    return a > b ? (a = b, true) : false;
}
template<class X, class Y> bool maximize(X &a, Y b) {
    return a < b ? (a = b, true) : false;
}
template<class X, class Y> bool add(X &a, Y b) {
    a += b;
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return true;
}

int n, s, e;
int f[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    // freopen(file".inp", "r",stdin);
    // freopen(file".out", "w",stdout);

    cin >> n >> s >> e;

    f[0][0] = 1;

    for (int i = 0; i < n; ++i) for (int j = 0; j <= i; ++j) {
        if (i + 1 == s || i + 1 == e) {
            // one place

            // one
            add(f[i + 1][j + 1], f[i][j]);

            // append
            add(f[i + 1][j], f[i][j]);
        } else {
            // create new one
            add(f[i + 1][j + 1], 1LL * f[i][j] * (j + 1 - (i + 1 > s) - (i + 1 > e)));

            // we can't append

            // unite
            if (j > 0) add(f[i + 1][j - 1], 1LL * f[i][j] * (j - 1) % mod);
        }
    }

    cout << f[n][1];
    
    return 0;
}

/*
restriction
a[i] < a[j] > a[k]
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -