Submission #1034275

# Submission time Handle Problem Language Result Execution time Memory
1034275 2024-07-25T11:36:55 Z toan2602 Tents (JOI18_tents) C++14
0 / 100
0 ms 348 KB
#include<bits/stdc++.h>

using namespace std;
#define int long long
const int mod = 1e9+7;
int n, m, dp[3005][3005];
int bp(int a, int b) {
	int res = 1;
	while(b) {
		if(b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}
void solve() {
	cin >> n >> m;
	dp[1][1] = 4;
	int r2 = bp(2, mod-2);
	dp[0][0] = dp[0][1] = dp[1][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if(i==1 && j==1) continue;
			dp[i][j] = dp[i-1][j] + dp[i-1][j-1] * j %mod * 4, dp[i][j] %= mod;
			if(j>=2)dp[i][j] += (dp[i-1][j-2] * m  % mod * (n-1) %mod * r2), dp[i][j] %= mod;
			if(i>=2)dp[i][j] += (dp[i-2][j-1] * n  % mod * (m-1) %mod * r2), dp[i][j] %= mod;
		}
	}
	cout << dp[n][m];
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen("input.inp","r")){
		freopen("input.inp", "r", stdin);
		freopen("output.out", "w", stdout);
	}
	int t = 1;
	// cin >> t;
	while(t--) {
		solve();
	}
}

Compilation message

tents.cpp: In function 'int main()':
tents.cpp:35:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   freopen("input.inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
tents.cpp:36:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |   freopen("output.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -