Submission #198252

# Submission time Handle Problem Language Result Execution time Memory
198252 2020-01-25T08:54:10 Z quocnguyen1012 Tents (JOI18_tents) C++14
100 / 100
287 ms 35832 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 < maxn; ++i)
    f[i][0] = 1, f[0][i] = 1;
  for (int i = 1; i <= N; ++i){
    for (int j = 1; j <= M; ++j){
      int & res = f[i][j];
      add(res,f[i - 1][j]);
      add(res,mul(f[i - 1][j - 1],4 * j));
      if (i > 1)  add(res,mul(f[i - 2][j - 1],j * (i - 1)));
      if (j > 1)  add(res,mul(f[i - 1][j - 2],j * (j - 1) / 2));
    }
  }
  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);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12408 KB Output is correct
2 Correct 13 ms 12408 KB Output is correct
3 Correct 12 ms 12408 KB Output is correct
4 Correct 11 ms 12408 KB Output is correct
5 Correct 12 ms 12664 KB Output is correct
6 Correct 12 ms 12536 KB Output is correct
7 Correct 12 ms 12536 KB Output is correct
8 Correct 12 ms 12408 KB Output is correct
9 Correct 11 ms 12408 KB Output is correct
10 Correct 13 ms 12668 KB Output is correct
11 Correct 12 ms 12408 KB Output is correct
12 Correct 15 ms 12764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12408 KB Output is correct
2 Correct 13 ms 12408 KB Output is correct
3 Correct 12 ms 12408 KB Output is correct
4 Correct 11 ms 12408 KB Output is correct
5 Correct 12 ms 12664 KB Output is correct
6 Correct 12 ms 12536 KB Output is correct
7 Correct 12 ms 12536 KB Output is correct
8 Correct 12 ms 12408 KB Output is correct
9 Correct 11 ms 12408 KB Output is correct
10 Correct 13 ms 12668 KB Output is correct
11 Correct 12 ms 12408 KB Output is correct
12 Correct 15 ms 12764 KB Output is correct
13 Correct 12 ms 12408 KB Output is correct
14 Correct 12 ms 12408 KB Output is correct
15 Correct 192 ms 33768 KB Output is correct
16 Correct 26 ms 13816 KB Output is correct
17 Correct 52 ms 17272 KB Output is correct
18 Correct 62 ms 18424 KB Output is correct
19 Correct 218 ms 35040 KB Output is correct
20 Correct 179 ms 31432 KB Output is correct
21 Correct 121 ms 25212 KB Output is correct
22 Correct 120 ms 25596 KB Output is correct
23 Correct 74 ms 19844 KB Output is correct
24 Correct 287 ms 35832 KB Output is correct
25 Correct 215 ms 32552 KB Output is correct
26 Correct 248 ms 34200 KB Output is correct
27 Correct 277 ms 35160 KB Output is correct