이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |