답안 #43984

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43984 2018-03-29T06:44:23 Z ruhanhabib39 Tents (JOI18_tents) C++17
100 / 100
122 ms 71340 KB
#include <bits/stdc++.h>
using namespace std;

const int MX = 3000;
const long long MOD = 1e9 + 7;

long long dp[MX + 10][MX + 10];

long long calc(long long H, long long W) {
   for(int w = 0; w <= W; w++) {
      dp[0][w] = 1;
   }
   for(int h = 0; h <= H; h++) {
      dp[h][0] = 1;
   }
   for(int h = 1; h <= H; h++) {
      for(int w = 1; w <= W; w++) {
         long long zero = dp[h-1][w];
         long long one = 4*w * dp[h-1][w-1] % MOD;
         long long two_horiz = 0, two_vert = 0;
         if(w >= 2) two_horiz = w*(w - 1) / 2 * dp[h-1][w-2] % MOD;
         if(h >= 2) two_vert = w * (h - 1) * dp[h-2][w-1] % MOD;
         dp[h][w] = (zero + one + two_horiz + two_vert) % MOD;
      }
   }
   return dp[H][W];
}

int main() {
   long long H, W; cin >> H >> W;
   cout << (calc(H, W) + MOD - 1) % MOD << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 1252 KB Output is correct
5 Correct 2 ms 1252 KB Output is correct
6 Correct 2 ms 1556 KB Output is correct
7 Correct 2 ms 1556 KB Output is correct
8 Correct 3 ms 1724 KB Output is correct
9 Correct 2 ms 1724 KB Output is correct
10 Correct 3 ms 2004 KB Output is correct
11 Correct 2 ms 2004 KB Output is correct
12 Correct 3 ms 2388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 1252 KB Output is correct
5 Correct 2 ms 1252 KB Output is correct
6 Correct 2 ms 1556 KB Output is correct
7 Correct 2 ms 1556 KB Output is correct
8 Correct 3 ms 1724 KB Output is correct
9 Correct 2 ms 1724 KB Output is correct
10 Correct 3 ms 2004 KB Output is correct
11 Correct 2 ms 2004 KB Output is correct
12 Correct 3 ms 2388 KB Output is correct
13 Correct 2 ms 2388 KB Output is correct
14 Correct 7 ms 9940 KB Output is correct
15 Correct 80 ms 55404 KB Output is correct
16 Correct 7 ms 55404 KB Output is correct
17 Correct 19 ms 55404 KB Output is correct
18 Correct 25 ms 55404 KB Output is correct
19 Correct 91 ms 63228 KB Output is correct
20 Correct 73 ms 63228 KB Output is correct
21 Correct 51 ms 63228 KB Output is correct
22 Correct 51 ms 63228 KB Output is correct
23 Correct 33 ms 63228 KB Output is correct
24 Correct 122 ms 71340 KB Output is correct
25 Correct 92 ms 71340 KB Output is correct
26 Correct 110 ms 71340 KB Output is correct
27 Correct 118 ms 71340 KB Output is correct