답안 #256610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256610 2020-08-03T00:51:39 Z cjoa Tents (JOI18_tents) C++11
100 / 100
295 ms 35936 KB
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int MOD = 1e9 + 7;

llong Choose2(int n) {
   return n * 1LL * (n-1) / 2;
}

int memo[3004][3004];
int go(int R, int C) {
   assert(R >= 0 && C >= 0);
// if (R < 0 || C < 0) return 0;
   if (R == 0 || C == 0) return 1;
   int& res = memo[R][C];
   if (res < 0) {
      res = go(R-1, C);  // do not place a tent in last row

      // place single tent in last row and one of the remaining columns (and
      // no other in same column
      llong add = go(R-1, C-1) * 4LL * C;
      res = (res + add) % MOD;

      // place two tents in the last row
      if (C >= 2) {
         add = go(R-1, C-2) * Choose2(C);
         res = (res + add) % MOD;
      }
 
      // place two tents in the same column, one of which is in last row
      if (R >= 2) {
         add = go(R-2, C-1) * 1LL * (R-1) * C;
         res = (res + add) % MOD;
      }
   }
   return res;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int R, C;
   cin >> R >> C;

   memset(memo, -1, sizeof(memo));
   int res = go(R, C);

   // remove case where no tent was placed
   res = (res + MOD - 1) % MOD;

   cout << res << '\n';

   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 35584 KB Output is correct
2 Correct 19 ms 35712 KB Output is correct
3 Correct 20 ms 35712 KB Output is correct
4 Correct 21 ms 35712 KB Output is correct
5 Correct 19 ms 35712 KB Output is correct
6 Correct 19 ms 35712 KB Output is correct
7 Correct 18 ms 35712 KB Output is correct
8 Correct 19 ms 35712 KB Output is correct
9 Correct 19 ms 35712 KB Output is correct
10 Correct 20 ms 35712 KB Output is correct
11 Correct 19 ms 35712 KB Output is correct
12 Correct 22 ms 35712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 35584 KB Output is correct
2 Correct 19 ms 35712 KB Output is correct
3 Correct 20 ms 35712 KB Output is correct
4 Correct 21 ms 35712 KB Output is correct
5 Correct 19 ms 35712 KB Output is correct
6 Correct 19 ms 35712 KB Output is correct
7 Correct 18 ms 35712 KB Output is correct
8 Correct 19 ms 35712 KB Output is correct
9 Correct 19 ms 35712 KB Output is correct
10 Correct 20 ms 35712 KB Output is correct
11 Correct 19 ms 35712 KB Output is correct
12 Correct 22 ms 35712 KB Output is correct
13 Correct 18 ms 35712 KB Output is correct
14 Correct 19 ms 35840 KB Output is correct
15 Correct 171 ms 35840 KB Output is correct
16 Correct 23 ms 35712 KB Output is correct
17 Correct 34 ms 35712 KB Output is correct
18 Correct 56 ms 35712 KB Output is correct
19 Correct 220 ms 35840 KB Output is correct
20 Correct 169 ms 35840 KB Output is correct
21 Correct 101 ms 35712 KB Output is correct
22 Correct 118 ms 35840 KB Output is correct
23 Correct 74 ms 35840 KB Output is correct
24 Correct 292 ms 35936 KB Output is correct
25 Correct 200 ms 35840 KB Output is correct
26 Correct 241 ms 35916 KB Output is correct
27 Correct 295 ms 35928 KB Output is correct