Submission #46431

# Submission time Handle Problem Language Result Execution time Memory
46431 2018-04-20T15:37:44 Z chpipis Tents (JOI18_tents) C++11
100 / 100
112 ms 36028 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)

// START for segment tree
#define params int p, int L, int R
#define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1
// END

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ldouble;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

//#ifdef LOCAL_MACHINE
//#endif

const int MOD = 1e9 + 7;
const int MAXN = 3005;

inline int mul_mod(int a, int b) {
    return a * 1LL * b % MOD;
}

inline void add_mod(int &a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

inline void sub_mod(int &a, int b) {
    a -= b;
    if (a < 0) a += MOD;
}

int dp[MAXN][MAXN];

int main() {
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i <= n; i++)
        dp[i][0] = 1;
    for (int j = 0; j <= m; j++)
        dp[0][j] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = mul_mod(dp[i - 1][j - 1], 4 * j);
            add_mod(dp[i][j], dp[i - 1][j]);
            if (j >= 2)
                add_mod(dp[i][j], mul_mod(j * (j - 1) / 2, dp[i - 1][j - 2]));
            if (i >= 2)
                add_mod(dp[i][j], mul_mod(j * (i - 1), dp[i - 2][j - 1]));
        }
    }
    sub_mod(dp[n][m], 1);
    printf("%d\n", dp[n][m]);
    return 0;
}

Compilation message

tents.cpp: In function 'int main()':
tents.cpp:80:10: 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 2 ms 376 KB Output is correct
2 Correct 2 ms 496 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 1368 KB Output is correct
5 Correct 2 ms 1368 KB Output is correct
6 Correct 3 ms 1596 KB Output is correct
7 Correct 2 ms 1596 KB Output is correct
8 Correct 3 ms 1620 KB Output is correct
9 Correct 2 ms 1620 KB Output is correct
10 Correct 3 ms 2068 KB Output is correct
11 Correct 2 ms 2068 KB Output is correct
12 Correct 4 ms 2204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 496 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 1368 KB Output is correct
5 Correct 2 ms 1368 KB Output is correct
6 Correct 3 ms 1596 KB Output is correct
7 Correct 2 ms 1596 KB Output is correct
8 Correct 3 ms 1620 KB Output is correct
9 Correct 2 ms 1620 KB Output is correct
10 Correct 3 ms 2068 KB Output is correct
11 Correct 2 ms 2068 KB Output is correct
12 Correct 4 ms 2204 KB Output is correct
13 Correct 2 ms 2204 KB Output is correct
14 Correct 8 ms 10020 KB Output is correct
15 Correct 83 ms 33360 KB Output is correct
16 Correct 7 ms 33360 KB Output is correct
17 Correct 20 ms 33360 KB Output is correct
18 Correct 24 ms 33360 KB Output is correct
19 Correct 89 ms 34968 KB Output is correct
20 Correct 73 ms 34968 KB Output is correct
21 Correct 48 ms 34968 KB Output is correct
22 Correct 50 ms 34968 KB Output is correct
23 Correct 38 ms 34968 KB Output is correct
24 Correct 112 ms 36028 KB Output is correct
25 Correct 88 ms 36028 KB Output is correct
26 Correct 101 ms 36028 KB Output is correct
27 Correct 111 ms 36028 KB Output is correct