Submission #272558

# Submission time Handle Problem Language Result Execution time Memory
272558 2020-08-18T12:34:11 Z erray Tents (JOI18_tents) C++17
100 / 100
186 ms 70992 KB
// author: erray
#include<bits/stdc++.h>
 
using namespace std;

template<typename T, typename F> string to_string(pair<T, F> p);
string to_string(string s) {
  return '"' + s + '"';
}
string to_string(char c) {
  return (string) "'" + c + "'";
}
string to_string(const char* p) {
  return to_string((string) p);
}
string to_string(bool B) {
  return (B ? "true" : "false");
}
string to_string(vector<bool> v) {
  string res = "{";
  for (int i = 0; i < (int) v.size(); ++i) {
    if ((int) res.size() > 1) res += ", ";
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template<size_t T> string to_string(bitset<T> bs) {
  return bs.to_string();
}
template<typename T> string to_string(T v) {
  string res = "{";
  for (auto& el : v) {
    if ((int) res.size() > 1) res += ", ";
    res += to_string(el);
  }
  res += "}";
  return res;
}
template<typename T, typename F> string to_string(pair<T, F> p) {
  return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
void debug_out() {
  cerr << endl;
}
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" , debug_out(__VA_ARGS__)
#else
#define debug(...) (void) 37
#endif

const int mod = (int) 1e9 + 7;  

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<vector<long long>> dp(h + 1, vector<long long>(w + 1, 1LL));
  auto get = [&](int x, int y) {
    if (x < 0 || y < 0) return 0LL;
    return dp[x][y];
  };
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      dp[i][j] = dp[i - 1][j];
      (dp[i][j] += get(i - 1, j - 1) * 4 * j % mod) %= mod; 
      (dp[i][j] += get(i - 2, j - 1) * (i - 1) % mod * j % mod) %= mod;      
      (dp[i][j] += get(i - 1, j - 2) * (j * (j - 1) / 2)) %= mod;
    }
  }
  debug(dp);
  cout << (dp[h][w] - 1 + mod) % mod << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 616 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 3 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 616 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 3 ms 1024 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 121 ms 44288 KB Output is correct
16 Correct 8 ms 3200 KB Output is correct
17 Correct 30 ms 10112 KB Output is correct
18 Correct 32 ms 12544 KB Output is correct
19 Correct 135 ms 51492 KB Output is correct
20 Correct 120 ms 41208 KB Output is correct
21 Correct 71 ms 27264 KB Output is correct
22 Correct 71 ms 26880 KB Output is correct
23 Correct 46 ms 15160 KB Output is correct
24 Correct 186 ms 70992 KB Output is correct
25 Correct 137 ms 52728 KB Output is correct
26 Correct 162 ms 60408 KB Output is correct
27 Correct 182 ms 68216 KB Output is correct