Submission #47432

# Submission time Handle Problem Language Result Execution time Memory
47432 2018-05-03T03:41:20 Z Just_Solve_The_Problem Tents (JOI18_tents) C++11
100 / 100
495 ms 71616 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define ll long long
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define ok puts("ok");
#define whatis(x) cerr << #x << " = " << x << endl;
#define pause system("pause");
#define random rand() ^ (rand() << 5)

const int N = (int)3e3 + 7;
const int inf = (int)1e9 + 7;
int mod = 1e9 + 7;

ll add(ll a, ll b) {
  a += b;
  if (a > mod) a -= mod;
  return a;
}

ll mult(ll a, ll b) {
  return a * b % mod;
}

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

main() {
  for (int i = 0; i < N; i++)
    dp[0][i] = dp[i][0] = 1;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ll &res = dp[i][j];
      if (j > 1)
        res = add(res, mult(dp[i - 1][j - 2], j * (j - 1) / 2));
      res = add(res, mult(dp[i - 1][j - 1], 4 * j));
      if (i > 1)
        res = add(res, mult(dp[i - 2][j - 1], j * (i - 1)));
      res = add(res, dp[i - 1][j]);
    }
  }
  printf("%lld", (dp[n][m] - 1 + mod) % mod);
}

Compilation message

tents.cpp:36:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
tents.cpp: In function 'int main()':
tents.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12664 KB Output is correct
2 Correct 9 ms 12824 KB Output is correct
3 Correct 9 ms 12936 KB Output is correct
4 Correct 10 ms 12936 KB Output is correct
5 Correct 10 ms 13244 KB Output is correct
6 Correct 10 ms 13244 KB Output is correct
7 Correct 10 ms 13244 KB Output is correct
8 Correct 10 ms 13244 KB Output is correct
9 Correct 10 ms 13244 KB Output is correct
10 Correct 12 ms 13312 KB Output is correct
11 Correct 29 ms 13312 KB Output is correct
12 Correct 14 ms 13708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12664 KB Output is correct
2 Correct 9 ms 12824 KB Output is correct
3 Correct 9 ms 12936 KB Output is correct
4 Correct 10 ms 12936 KB Output is correct
5 Correct 10 ms 13244 KB Output is correct
6 Correct 10 ms 13244 KB Output is correct
7 Correct 10 ms 13244 KB Output is correct
8 Correct 10 ms 13244 KB Output is correct
9 Correct 10 ms 13244 KB Output is correct
10 Correct 12 ms 13312 KB Output is correct
11 Correct 29 ms 13312 KB Output is correct
12 Correct 14 ms 13708 KB Output is correct
13 Correct 9 ms 13708 KB Output is correct
14 Correct 9 ms 13708 KB Output is correct
15 Correct 286 ms 56736 KB Output is correct
16 Correct 27 ms 56736 KB Output is correct
17 Correct 70 ms 56736 KB Output is correct
18 Correct 88 ms 56736 KB Output is correct
19 Correct 362 ms 63984 KB Output is correct
20 Correct 262 ms 63984 KB Output is correct
21 Correct 175 ms 63984 KB Output is correct
22 Correct 181 ms 63984 KB Output is correct
23 Correct 103 ms 63984 KB Output is correct
24 Correct 430 ms 71616 KB Output is correct
25 Correct 359 ms 71616 KB Output is correct
26 Correct 402 ms 71616 KB Output is correct
27 Correct 495 ms 71616 KB Output is correct