Submission #201804

# Submission time Handle Problem Language Result Execution time Memory
201804 2020-02-12T03:42:51 Z EntityIT Tents (JOI18_tents) C++14
100 / 100
129 ms 35832 KB
#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;

const int mod = 1e9 + 7;
mt19937 rng( (uint32_t)chrono::steady_clock::now().time_since_epoch().count() );

struct Mint {
  int a;
  Mint(int _a = 0) : a(_a) {}
  friend ostream& operator << (ostream &out, const Mint &_) {
    out << _.a;
    return out;
  }

  bool operator == (const Mint &_) const { return a == _.a; }
  bool operator ! () const { return !a; }

  Mint operator + (const Mint &_) const {
    int ret = a + _.a;
    return ret < mod ? Mint(ret) : Mint(ret - mod);
  }
  Mint operator - (const Mint &_) const { return *this + Mint(mod - _.a); }
  Mint operator * (const Mint &_) const { return Mint( (int)( (LL)a * _.a % mod) ); }
  friend Mint& operator += (Mint &a, const Mint &b) { return a = a + b; }
  friend Mint& operator -= (Mint &a, const Mint &b) { return a = a - b; }
  friend Mint& operator *= (Mint &a, const Mint &b) { return a = a * b; }
  Mint& operator ++ () { return *this = *this + Mint(1); }
  Mint& operator -- () { return *this = *this - Mint(1); }

  template<class T> Mint binPow(T exp) const {
    Mint ret(1), c = *this;
    for (; exp; exp >>= 1, c *= c) if (exp & 1) ret *= c;
    return ret;
  }
};

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);

  #ifdef FourLeafClover
  freopen("input", "r", stdin);
  #endif // FourLeafCLover

  int n, m; cin >> n >> m;

  vector<vector<Mint> > f(n + 1, vector<Mint>(m + 1) );
  for (int i = 0; i < n; ++i) f[i][0] = Mint(1);
  for (int j = 0; j < m; ++j) f[0][j] = Mint(1);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      f[i][j] += f[i - 1][j];
      f[i][j] += f[i - 1][j - 1] * Mint(4 * j);
      if (j > 1) f[i][j] += f[i - 1][j - 2] * Mint(j * (j - 1) / 2);
      if (i > 1) f[i][j] += f[i - 2][j - 1] * Mint(j * (i - 1) );
    }
  }

  cout << f[n][m] << '\n';

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 6 ms 504 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 380 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 6 ms 504 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 380 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 508 KB Output is correct
15 Correct 82 ms 22392 KB Output is correct
16 Correct 10 ms 1656 KB Output is correct
17 Correct 23 ms 5240 KB Output is correct
18 Correct 26 ms 6392 KB Output is correct
19 Correct 98 ms 25976 KB Output is correct
20 Correct 77 ms 20856 KB Output is correct
21 Correct 52 ms 13816 KB Output is correct
22 Correct 53 ms 13688 KB Output is correct
23 Correct 32 ms 7800 KB Output is correct
24 Correct 129 ms 35832 KB Output is correct
25 Correct 98 ms 26616 KB Output is correct
26 Correct 112 ms 30456 KB Output is correct
27 Correct 125 ms 34296 KB Output is correct