제출 #1294258

#제출 시각아이디문제언어결과실행 시간메모리
1294258ezim1234캥거루 (CEOI16_kangaroo)C++20
0 / 100
1 ms568 KiB
#include <bits/stdc++.h>
using namespace std;

#define all(v) v.begin(), v.end()
#define yes cout << "Yes" << "\n"
#define no cout << "No" << "\n"
#define pb push_back
#define F first
#define S second
#define int long long
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll, ll> pii;
typedef vector <pii> vii;
typedef vector <ll> vi;
template<typename T>
void read(vector<T>& v) {
    for (auto &x : v) cin >> x;
}

template<typename T>
void print(const vector<T>& v) {
    for (auto &x : v) cout << x << ' ';
    cout << "\n";
}

const ll MAX = 2000 + 5;
const ll MOD = 1e9 + 7;
int dp[MAX][MAX];
int dp1[MAX][MAX];
void solve() {
    int n, s, f;
    cin >> n >> s >> f;
    if (n == 2) {
        cout << 1 << '\n';
        return;
    }
    for (int i = 1; i <= n; i++) {
        if (i == n) {
            int cem = 0;
            for (int j = 1; j <= n; j++) {
                cem += dp[i - 1][j];
                cem += dp1[i - 1][j];
                cem = cem % MOD;
            }
            cout << cem << '\n';
            return;
        }
        if (i == 1) {
            dp[i][s] = 1;
            dp1[i][s] = 1;
            continue;
        }
        int cem = 0;
        int say = 0;
        for (int j = 1; j <= n; j++) {
            if (j != s && j != f) {
                dp[i][j] = cem - dp[i - 2][j] * 2;
            }
            cem += dp1[i - 1][j];
            say++;
        }
        cem = 0;
        say = 0;
        for (int j = n; j >= 1; j--) {
            if (j != s && j != f) {
                dp1[i][j] = cem - dp1[i - 2][j] * 2;
            }
            cem += dp[i - 1][j];
            say++;
        }
    }
    cout << dp[n][f] + dp1[n][f] << '\n';
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...