답안 #198243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198243 2020-01-25T08:46:52 Z quocnguyen1012 Tents (JOI18_tents) C++14
0 / 100
6 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(j, i - 1) * f[i - 2][j - 1] % mod);
    }
  }
  add(f[N][M], -1);
  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);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -