Submission #101067

#TimeUsernameProblemLanguageResultExecution timeMemory
101067ecasdqinaTents (JOI18_tents)C++14
100 / 100
323 ms71032 KiB
#include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = long long; using std::cout; using std::endl; using std::cin; const int MOD = 1e9 + 7; i64 mod_pow(i64 x, i64 n = MOD - 2) { i64 ret = 1; while(n) { if(n & 1) (ret *= x) %= MOD; (x *= x) %= MOD; n >>= 1; } return ret; } std::vector<i64> fact, inv; i64 comb(int n, int r) { return fact[n] * inv[n - r] % MOD * inv[r] % MOD; } int main() { int h, w; scanf("%d%d", &h, &w); // assert(h <= 300 and w <= 300); fact.assign(std::max(h, w) + 1, 1); inv.assign(std::max(h, w) + 1, 1); for(int i = 0; i < std::max(h, w); i++) fact[i + 1] = fact[i] * (i64)(i + 1) % MOD; for(int i = 0; i <= std::max(h, w); i++) inv[i] = mod_pow(fact[i]); std::vector<std::vector<i64>> dp(h + 1, std::vector<i64>(w + 1, 0)); dp[h][w] = 1; for(i64 i = h; i >= 0; i--) { for(i64 j = w; j >= 0; j--) { if(i >= 1 and j >= 1) { dp[i - 1][j - 1] += dp[i][j] * j % MOD * 4; dp[i - 1][j - 1] %= MOD; } if(i >= 1 and j >= 2) { dp[i - 1][j - 2] += dp[i][j] * comb(j, 2) % MOD; dp[i - 1][j - 2] %= MOD; } if(i >= 2 and j >= 1) { dp[i - 2][j - 1] += dp[i][j] * j % MOD * (i - 1) % MOD; dp[i - 2][j - 1] %= MOD; } if(i >= 1) { dp[i - 1][j] += dp[i][j]; dp[i - 1][j] %= MOD; } } } i64 ans = 0; for(int j = 0; j <= w; j++) (ans += dp[0][j]) %= MOD; printf("%lld\n", (ans - 1 + MOD) % MOD); return 0; }

Compilation message (stderr)

tents.cpp: In function 'int main()':
tents.cpp:26:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int h, w; scanf("%d%d", &h, &w);
            ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...