Submission #46561

# Submission time Handle Problem Language Result Execution time Memory
46561 2018-04-21T12:19:48 Z nickyrio Tents (JOI18_tents) C++17
100 / 100
157 ms 71952 KB
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define DEBUG(x) { cerr << #x << '=' << x << endl; }
#define Arr(a, l, r) { cerr << #a << " = {"; FOR(_, l, r) cerr << ' ' << a[_]; cerr << "}\n"; }
#define N 3030
#define pp pair<int, int>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define taskname ""
#define bit(S, i) (((S) >> (i)) & 1)
using namespace std;
const long long MOD = 1e9 + 7;
long long dp[N][N];
void Add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

void Solve() {
    int m, n;
    cin >> m >> n;
    FOR(i, 0, m) dp[i][0] = 1;
    FOR(i, 0, n) dp[0][i] = 1;
    FOR(i, 1, m) FOR(j, 1, n) {
        // Put no tent at row i
        Add(dp[i][j], dp[i - 1][j]);
        // Put just a tent at row i
        Add(dp[i][j], dp[i - 1][j - 1] * 4ll * j % MOD);
        // Put a tent at row i and another tent at the same column
        if (i > 1) Add(dp[i][j], dp[i - 2][j - 1] * (i - 1) * j % MOD);
        // Put two tent at row i
        if (j > 1) Add(dp[i][j], dp[i - 1][j - 2] * ((j - 1) * j / 2) % MOD); 
    }
    cout << (dp[m][n] - 1 + MOD) % MOD;
}
int main() {
    #ifdef NERO
    freopen("test.inp","r",stdin);
    freopen("test.out","w",stdout);
    double stime = clock();
    #else 
        //freopen(taskname".inp","r",stdin);
        //freopen(taskname".out","w",stdout);
    #endif //NERO
    IO;
    Solve();
    #ifdef NERO
    double etime = clock();
    cerr << "Execution time: " << (etime - stime) / CLOCKS_PER_SEC * 1000 << " ms.\n";
    #endif // NERO
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
4 Correct 2 ms 1424 KB Output is correct
5 Correct 2 ms 1424 KB Output is correct
6 Correct 3 ms 1788 KB Output is correct
7 Correct 2 ms 1788 KB Output is correct
8 Correct 3 ms 1788 KB Output is correct
9 Correct 2 ms 1788 KB Output is correct
10 Correct 3 ms 2120 KB Output is correct
11 Correct 2 ms 2120 KB Output is correct
12 Correct 5 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
4 Correct 2 ms 1424 KB Output is correct
5 Correct 2 ms 1424 KB Output is correct
6 Correct 3 ms 1788 KB Output is correct
7 Correct 2 ms 1788 KB Output is correct
8 Correct 3 ms 1788 KB Output is correct
9 Correct 2 ms 1788 KB Output is correct
10 Correct 3 ms 2120 KB Output is correct
11 Correct 2 ms 2120 KB Output is correct
12 Correct 5 ms 2680 KB Output is correct
13 Correct 2 ms 2680 KB Output is correct
14 Correct 9 ms 10076 KB Output is correct
15 Correct 116 ms 55588 KB Output is correct
16 Correct 11 ms 55588 KB Output is correct
17 Correct 29 ms 55588 KB Output is correct
18 Correct 44 ms 55588 KB Output is correct
19 Correct 138 ms 63408 KB Output is correct
20 Correct 99 ms 63408 KB Output is correct
21 Correct 67 ms 63408 KB Output is correct
22 Correct 67 ms 63408 KB Output is correct
23 Correct 44 ms 63408 KB Output is correct
24 Correct 157 ms 71952 KB Output is correct
25 Correct 125 ms 71952 KB Output is correct
26 Correct 138 ms 71952 KB Output is correct
27 Correct 152 ms 71952 KB Output is correct