답안 #67267

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67267 2018-08-13T18:33:24 Z kingpig9 Tents (JOI18_tents) C++11
100 / 100
146 ms 36036 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 3018, MOD = 1e9 + 7;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define fillchar(a, s) memset((a), (s), sizeof(a))

void addeq (int &x, int y) {
	x += y;
	if (x >= MOD) {
		x -= MOD;
	}
}

int mult (int x, int y) {
	return ll(x) * y % MOD;
}

int N, M;
int dp[MAXN][MAXN];

int main() {
	scanf("%d %d", &N, &M);
	for (int j = 0; j <= M; j++) {
		dp[0][j] = 1;
	}
	for (int i = 0; i <= N; i++) {
		dp[i][0] = 1;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			int &ref = dp[i][j];

			addeq(ref, mult(4 * j, dp[i - 1][j - 1]));	//put one on this row
			addeq(ref, dp[i - 1][j]);	//put nothing on this row

			if (j > 1) {
				addeq(ref, mult(j * (j - 1) / 2, dp[i - 1][j - 2]));	//2 points on the same row
			}
			if (i > 1) {
				addeq(ref, mult((i - 1) * j, dp[i - 2][j - 1]));
			}
		}
	}
	printf("%d\n", dp[N][M] - 1);
}

Compilation message

tents.cpp: In function 'int main()':
tents.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 576 KB Output is correct
4 Correct 3 ms 1252 KB Output is correct
5 Correct 3 ms 1252 KB Output is correct
6 Correct 3 ms 1432 KB Output is correct
7 Correct 3 ms 1432 KB Output is correct
8 Correct 4 ms 1544 KB Output is correct
9 Correct 3 ms 1544 KB Output is correct
10 Correct 5 ms 1904 KB Output is correct
11 Correct 2 ms 1904 KB Output is correct
12 Correct 5 ms 2060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 576 KB Output is correct
4 Correct 3 ms 1252 KB Output is correct
5 Correct 3 ms 1252 KB Output is correct
6 Correct 3 ms 1432 KB Output is correct
7 Correct 3 ms 1432 KB Output is correct
8 Correct 4 ms 1544 KB Output is correct
9 Correct 3 ms 1544 KB Output is correct
10 Correct 5 ms 1904 KB Output is correct
11 Correct 2 ms 1904 KB Output is correct
12 Correct 5 ms 2060 KB Output is correct
13 Correct 2 ms 2060 KB Output is correct
14 Correct 9 ms 9880 KB Output is correct
15 Correct 101 ms 33284 KB Output is correct
16 Correct 11 ms 33284 KB Output is correct
17 Correct 23 ms 33284 KB Output is correct
18 Correct 28 ms 33284 KB Output is correct
19 Correct 106 ms 34948 KB Output is correct
20 Correct 86 ms 34948 KB Output is correct
21 Correct 60 ms 34948 KB Output is correct
22 Correct 62 ms 34948 KB Output is correct
23 Correct 37 ms 34948 KB Output is correct
24 Correct 146 ms 36036 KB Output is correct
25 Correct 107 ms 36036 KB Output is correct
26 Correct 117 ms 36036 KB Output is correct
27 Correct 124 ms 36036 KB Output is correct