Submission #605448

#TimeUsernameProblemLanguageResultExecution timeMemory
605448MadokaMagicaFanKangaroo (CEOI16_kangaroo)C++14
100 / 100
23 ms31592 KiB
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
const int md1 = 1e9+7;
const int N = 2000;
ll dp[N+1][N+5]; 

void
solve()
{
    int n, s, t;
    cin >> n >> s >> t;

    if (s > t) swap(s,t);

    s -= 2;
    t -= 2;
    dp[0][1] = 1;
    for (int i = 0; i < n-2; ++i) {
        for (ll j = 1; j < n+1; ++j) {
                if (i < s) dp[i+1][j] = (dp[i][j-1] + (j+1)*j*dp[i][j+1]) % md1;
                else if (i == s) dp[i+1][j] = (dp[i][j-1] + j*dp[i][j]) % md1;
                else if (i <  t) dp[i+1][j] = (dp[i][j-1] + j*j*dp[i][j+1]) % md1;
                else if (i == t) dp[i+1][j] = (dp[i][j] + j*dp[i][j+1]) % md1;
                else dp[i+1][j] = (dp[i][j-1] + (j+1)*j*dp[i][j+1]) % md1;
        }
    }
    cout << dp[n-2][1] << endl;
}

int32_t
main(int argc, char **argv)
{
    if (argc >= 2) {
        freopen(argv[1], "r", stdin);
    } else
        ios_base::sync_with_stdio(0);cin.tie(0);
    solve();
}

Compilation message (stderr)

kangaroo.cpp: In function 'int32_t main(int, char**)':
kangaroo.cpp:38:7: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   38 |     } else
      |       ^~~~
kangaroo.cpp:39:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   39 |         ios_base::sync_with_stdio(0);cin.tie(0);
      |                                      ^~~
kangaroo.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen(argv[1], "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...