Submission #307370

# Submission time Handle Problem Language Result Execution time Memory
307370 2020-09-28T02:49:33 Z jungsnow Kangaroo (CEOI16_kangaroo) C++14
6 / 100
1 ms 384 KB
#include<bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;
const int N = 2001;

void add(int& a, int b) {
    a += b;
    while (a >= b) a -= mod;
    while (a < 0)  a += mod;
}

void mul(int& a, int b) {
    a = 1ll * a * b % mod;
}

int st, en, n;
int dp[N][N][4];
/// 0 - 00; 1 - 10, 2 - 01, 3 - 11;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("kangaroo.in", "r", stdin);
//    freopen("kangaroo.out", "w", stdout);
    cin>>n>>st>>en;
    dp[0][0][0] = 1;
    int cur = 0;
    for (int i = 0; i < n - 2; ++i) {
        ++cur;
        if (cur == st) ++cur;
        if (cur == en) ++cur;
//        cerr<<cur<<'\n';
        for (int j = 0; j <= i; ++j) {
            for (int k = 0; k < 4; ++k) {
                if (dp[i][j][k] == 0) continue;
                for (int t = 0; t < 2; ++t) if ((k >> t & 1) == 0){
                    int m = (t == 0 ? st : en);
                    if (cur > m && j > 0) add(dp[i + 1][j - 1][k | (1 << t)], 1ll * dp[i][j][k] * j % mod);
                    else add(dp[i + 1][j][k | (1 << t)], dp[i][j][k]);
                }
                add(dp[i + 1][j + 1][k], dp[i][j][k]);
                if (j > 1) add(dp[i + 1][j - 1][k], 1ll * (dp[i][j][k] * j) % mod * (j - 1) % mod);
            }
        }
    }
    cout << dp[n - 2][0][3];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -