답안 #900516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900516 2024-01-08T12:11:02 Z guechotjrhh Tents (JOI18_tents) C++14
100 / 100
69 ms 492 KB
#include<iostream>
#include<vector>
using namespace std;
#define ll long long
int mod = 1e9 + 7;

int func(int n, int m) {
	vector<ll> dp1(m+1, 0), dp2(m+1, 0), dp3(m+1, 0);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			dp3[j] = dp2[j]; //empty
			dp3[j] += (1 + dp2[j-1]) * 4 * j; //one, not connected
			if (j > 1) dp3[j] += (1 + dp2[j - 2]) * (j * (j-1))/2; //2 in the row
			if (i > 0) dp3[j] += (1 + dp1[j-1]) * j  * (i-1);//one col, 2 in the col
			dp3[j] %= mod;
		}
		dp1 = dp2;
		dp2 = dp3;
	}
	return dp2[m];
}

int main() {
	int n, m;
	cin >> n >> m;

	cout << func(n, m) << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 43 ms 348 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 10 ms 344 KB Output is correct
18 Correct 11 ms 348 KB Output is correct
19 Correct 50 ms 348 KB Output is correct
20 Correct 39 ms 348 KB Output is correct
21 Correct 26 ms 348 KB Output is correct
22 Correct 25 ms 348 KB Output is correct
23 Correct 13 ms 344 KB Output is correct
24 Correct 69 ms 348 KB Output is correct
25 Correct 51 ms 492 KB Output is correct
26 Correct 58 ms 344 KB Output is correct
27 Correct 66 ms 348 KB Output is correct