Submission #318210

# Submission time Handle Problem Language Result Execution time Memory
318210 2020-10-31T15:37:38 Z a14789654 Kangaroo (CEOI16_kangaroo) C++17
0 / 100
1 ms 364 KB
///https://oj.uz/problem/view/CEOI16_kangaroo
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2007, MOD = 1e9 + 7;

int cs, cf, n, f[MAXN][MAXN];

void add(int &a, int b)
{
    a += b;
    if (a >= MOD) a -= MOD;
}

int main()
{
    if (fopen("tst.inp", "r"))
    {
        freopen("tst.inp", "r", stdin);
        freopen("tst.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    cin >> n >> cs >> cf;
    if (cs > cf) swap(cs, cf);

    f[0][0] = 1;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= i + 1; ++j)
            if (i != cs && i != cf)
            {
                if (i < n && j) add(f[i + 1][j - 1], 1LL * f[i][j] * j * (j - 1) % MOD);
                if (i < n && j < n) add(f[i + 1][j + 1], f[i][j]);
                if (i > cs && i < n && j) add(f[i + 1][j - 1], 1LL * f[i][j] * j % MOD);
                if (i > cf && i < n && j) add(f[i + 1][j - 1], 1LL * f[i][j] * j % MOD);
            }
            else
            {
                add(f[i + 1][j], f[i][j]);
                if (j) add(f[i + 1][j - 1], 1LL * f[i][j] * j % MOD);
            }

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

Compilation message

kangaroo.cpp: In function 'int main()':
kangaroo.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   20 |         freopen("tst.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   21 |         freopen("tst.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct