Submission #443655

# Submission time Handle Problem Language Result Execution time Memory
443655 2021-07-11T07:42:48 Z fsociety00 Kangaroo (CEOI16_kangaroo) C++14
0 / 100
2 ms 332 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define LD long double

const int N = 100010;

int inf = 1e9;
int mod = 1e9 + 7;

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

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += mod;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % mod);
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= mod;
  if (a < 0) a += mod;
  int b = mod, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += mod;
  return u;
}


signed main()
{
    freopen("kangaroo.in", "r", stdin);
    freopen("kangaroo.out", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;
    cin >> n;

    int cs, cf;
    cin >> cs >> cf;

    int dp[n + 1][n + 2];
    memset(dp, 0, sizeof(dp));

    dp[1][1] = 1;

    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            if (i == cs || i == cf) {
                add(dp[i][j], dp[i - 1][j - 1]);
                add(dp[i][j], dp[i - 1][j]);
                continue;
            }
            add(dp[i][j], mul(j, dp[i - 1][j + 1]));
            int ins = j;
            if (i > cs) sub(ins, 1);
            if (i > cf) sub(ins, 1);
            add(dp[i][j], mul(ins, dp[i - 1][j - 1]));
        }
    }

    cout << dp[n][1] << "\n";

    return 0;
}

Compilation message

kangaroo.cpp: In function 'int main()':
kangaroo.cpp:55:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     freopen("kangaroo.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:56:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |     freopen("kangaroo.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -