Submission #82379

# Submission time Handle Problem Language Result Execution time Memory
82379 2018-10-30T11:05:57 Z MrTEK Tents (JOI18_tents) C++14
100 / 100
361 ms 36484 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

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

int n,m,dp[N][N];

inline int mul(int x,int y) {
  return (ll) x * y % mod;
}

inline int add(int x,int y) {
  return (x + y) % mod;
}

int f(int x,int y) {
  int &res = dp[x][y];
  if (res != -1)
    return res;
  if (x == 0 || y == 0)
    return 1;
  res = f(x - 1,y);
  if (y >= 2)
    res = add(res,mul(f(x - 1,y - 2),y * (y - 1) / 2));
  if (y >= 1)
    res = add(res,mul(f(x - 1,y -1),y * 4));
  if (x >= 2 && y >= 1)
    res = add(res,mul(f(x - 2,y - 1),mul(y,x - 1)));
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> m;
  memset(dp,-1,sizeof dp);
  cout << f(n,m) - 1 << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 32 ms 35704 KB Output is correct
2 Correct 30 ms 35704 KB Output is correct
3 Correct 38 ms 35864 KB Output is correct
4 Correct 31 ms 35864 KB Output is correct
5 Correct 31 ms 35864 KB Output is correct
6 Correct 38 ms 35864 KB Output is correct
7 Correct 31 ms 35872 KB Output is correct
8 Correct 39 ms 36000 KB Output is correct
9 Correct 32 ms 36000 KB Output is correct
10 Correct 32 ms 36076 KB Output is correct
11 Correct 32 ms 36076 KB Output is correct
12 Correct 33 ms 36076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 35704 KB Output is correct
2 Correct 30 ms 35704 KB Output is correct
3 Correct 38 ms 35864 KB Output is correct
4 Correct 31 ms 35864 KB Output is correct
5 Correct 31 ms 35864 KB Output is correct
6 Correct 38 ms 35864 KB Output is correct
7 Correct 31 ms 35872 KB Output is correct
8 Correct 39 ms 36000 KB Output is correct
9 Correct 32 ms 36000 KB Output is correct
10 Correct 32 ms 36076 KB Output is correct
11 Correct 32 ms 36076 KB Output is correct
12 Correct 33 ms 36076 KB Output is correct
13 Correct 35 ms 36076 KB Output is correct
14 Correct 31 ms 36108 KB Output is correct
15 Correct 230 ms 36256 KB Output is correct
16 Correct 32 ms 36256 KB Output is correct
17 Correct 51 ms 36256 KB Output is correct
18 Correct 86 ms 36256 KB Output is correct
19 Correct 277 ms 36324 KB Output is correct
20 Correct 217 ms 36324 KB Output is correct
21 Correct 129 ms 36324 KB Output is correct
22 Correct 143 ms 36348 KB Output is correct
23 Correct 105 ms 36352 KB Output is correct
24 Correct 327 ms 36484 KB Output is correct
25 Correct 245 ms 36484 KB Output is correct
26 Correct 274 ms 36484 KB Output is correct
27 Correct 361 ms 36484 KB Output is correct