Submission #198175

# Submission time Handle Problem Language Result Execution time Memory
198175 2020-01-25T02:34:19 Z quocnguyen1012 Tents (JOI18_tents) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

const int maxn = 3e3 + 5, mod = 1e9 + 7;

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

int mul(int a, int b)
{
  return 1ll * a * b % mod;
}

int N, M;
int f[maxn][maxn];

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N >> M;
  for (int i = 0; i <= N; ++i)
    f[i][0] = 1, f[0][i] = 1;
  for (int i = 1; i <= N; ++i){
    for (int j = 1; j <= M; ++j){
      add(f[i][j], f[i - 1][j]);
      if (j >= 2) add(f[i][j], 1ll * mul(j, j - 1) / 2 * f[i - 1][j - 2]);
      add(f[i][j], 1ll * mul(4, j) * f[i - 1][j - 1] % mod);
      if (i >= 2) add(f[i][j], 1ll * mul(M, N - 1) * f[N - 2][M - 1] % mod);
    }
  }
  cout << f[N][M] << '\n';
}

Compilation message

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