Submission #1971517
Source Code Expand
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- template<int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) { } ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; }; template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } typedef ModInt<1000000007> mint; /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ // http://d.hatena.ne.jp/incognita/20110305/1299344781 // todo: 他の実装 // Q(i,j) := 整数iを順序を区別せずに「j個の自然数」の和に分ける場合の数 // R(i,j) := 整数iを順序を区別せずに「j個以下の自然数」の和に分ける場合の数 template<typename T> struct PartitionNumber{ int n; vector<T> _P; vector<vector<T>> _PP, _Q, _R; PartitionNumber(int _n) { n = _n; _P.resize(n + 1); _PP.resize(n + 1, vector<T>(n + 1)); _Q.resize(n + 1, vector<T>(n + 1)); _R.resize(n + 1, vector<T>(n + 1)); _Q[0][0] = 1; rep(i, 1, n + 1) rep(j, 1, n + 1) { _Q[i][j] += _Q[i - 1][j - 1]; if (j <= i) _Q[i][j] += _Q[i - j][j]; } rep(i, 0, n + 1) { _R[i][0] = _Q[i][0]; rep(j, 1, n + 1) _R[i][j] = _R[i][j - 1] + _Q[i][j]; } } mint R(int i, int j) { assert(0 <= j and 0 <= i and j <= n and i <= n); return _R[i][j]; } }; //--------------------------------------------------------------------------------------------------- PartitionNumber<mint> pn(1010); mint solve(vector<int> &kill, vector<int>& death) { deque<pair<int, int>> cnt; cnt.push_back({ kill[0], 1 }); rep(i, 1, kill.size()) { if (cnt.back().first == kill[i]) cnt.back().second++; else cnt.push_back({ kill[i], 1 }); } int sm = 0; fore(i, death) sm += i; int n = cnt.size(); vector<vector<mint>> dp(n + 1, vector<mint>(sm + 1, 0)); dp[0][0] = 1; rep(g, 0, n) rep(s, 0, sm + 1) rep(i, 0, sm - s + 1) dp[g + 1][s + i] += dp[g][s] * pn.R(i, cnt[g].second); return dp[n][sm]; } //--------------------------------------------------------------------------------------------------- void _main() { int N, M; cin >> N >> M; vector<int> A(N), B(M); rep(i, 0, N) cin >> A[i]; rep(i, 0, M) cin >> B[i]; mint a = solve(A, B); mint b = solve(B, A); mint ans = a * b; cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - Kill/Death |
User | hamayanhamayan |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 5015 Byte |
Status | AC |
Exec Time | 385 ms |
Memory | 12672 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 500 / 500 | ||
Status |
|
Set Name | Test Cases |
---|---|
All | 01_sample00, 01_sample01, 01_sample02, 01_sample03, 01_sample04, 02_minimal00, 02_minimal01, 02_minimal02, 02_minimal03, 03_maximal00, 03_maximal01, 04_random-easy00, 04_random-easy01, 04_random-easy02, 04_random-easy03, 04_random-easy04, 04_random-easy05, 04_random-easy06, 04_random-easy07, 04_random-easy08, 04_random-easy09, 04_random-easy10, 04_random-easy11, 04_random-easy12, 04_random-easy13, 04_random-easy14, 04_random-easy15, 04_random-easy16, 04_random-easy17, 04_random-easy18, 04_random-easy19, 05_random-large00, 05_random-large01, 05_random-large02, 05_random-large03, 05_random-large04, 05_random-large05, 05_random-large06, 05_random-large07, 05_random-large08, 05_random-large09, 05_random-large10, 05_random-large11, 05_random-large12, 05_random-large13, 05_random-large14, 05_random-large15, 05_random-large16, 05_random-large17, 05_random-large18, 05_random-large19, 06_random00, 06_random01, 06_random02, 06_random03, 06_random04, 06_random05, 06_random06, 06_random07, 06_random08, 06_random09, 06_random10, 06_random11, 06_random12, 06_random13, 06_random14, 06_random15, 06_random16, 06_random17, 06_random18, 06_random19 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01_sample00 | AC | 17 ms | 12416 KB |
01_sample01 | AC | 17 ms | 12416 KB |
01_sample02 | AC | 17 ms | 12416 KB |
01_sample03 | AC | 17 ms | 12416 KB |
01_sample04 | AC | 18 ms | 12416 KB |
02_minimal00 | AC | 17 ms | 12416 KB |
02_minimal01 | AC | 21 ms | 12416 KB |
02_minimal02 | AC | 21 ms | 12416 KB |
02_minimal03 | AC | 26 ms | 12416 KB |
03_maximal00 | AC | 41 ms | 12416 KB |
03_maximal01 | AC | 26 ms | 12416 KB |
04_random-easy00 | AC | 17 ms | 12416 KB |
04_random-easy01 | AC | 17 ms | 12416 KB |
04_random-easy02 | AC | 17 ms | 12416 KB |
04_random-easy03 | AC | 17 ms | 12416 KB |
04_random-easy04 | AC | 17 ms | 12416 KB |
04_random-easy05 | AC | 17 ms | 12416 KB |
04_random-easy06 | AC | 17 ms | 12416 KB |
04_random-easy07 | AC | 17 ms | 12416 KB |
04_random-easy08 | AC | 17 ms | 12416 KB |
04_random-easy09 | AC | 17 ms | 12416 KB |
04_random-easy10 | AC | 17 ms | 12416 KB |
04_random-easy11 | AC | 17 ms | 12416 KB |
04_random-easy12 | AC | 17 ms | 12416 KB |
04_random-easy13 | AC | 17 ms | 12416 KB |
04_random-easy14 | AC | 17 ms | 12416 KB |
04_random-easy15 | AC | 17 ms | 12416 KB |
04_random-easy16 | AC | 17 ms | 12416 KB |
04_random-easy17 | AC | 17 ms | 12416 KB |
04_random-easy18 | AC | 17 ms | 12416 KB |
04_random-easy19 | AC | 17 ms | 12416 KB |
05_random-large00 | AC | 327 ms | 12544 KB |
05_random-large01 | AC | 385 ms | 12544 KB |
05_random-large02 | AC | 357 ms | 12544 KB |
05_random-large03 | AC | 341 ms | 12544 KB |
05_random-large04 | AC | 330 ms | 12544 KB |
05_random-large05 | AC | 369 ms | 12544 KB |
05_random-large06 | AC | 350 ms | 12672 KB |
05_random-large07 | AC | 348 ms | 12544 KB |
05_random-large08 | AC | 330 ms | 12544 KB |
05_random-large09 | AC | 336 ms | 12544 KB |
05_random-large10 | AC | 337 ms | 12544 KB |
05_random-large11 | AC | 334 ms | 12544 KB |
05_random-large12 | AC | 369 ms | 12544 KB |
05_random-large13 | AC | 354 ms | 12544 KB |
05_random-large14 | AC | 347 ms | 12544 KB |
05_random-large15 | AC | 314 ms | 12544 KB |
05_random-large16 | AC | 357 ms | 12544 KB |
05_random-large17 | AC | 361 ms | 12544 KB |
05_random-large18 | AC | 362 ms | 12544 KB |
05_random-large19 | AC | 344 ms | 12544 KB |
06_random00 | AC | 131 ms | 12416 KB |
06_random01 | AC | 18 ms | 12416 KB |
06_random02 | AC | 23 ms | 12416 KB |
06_random03 | AC | 151 ms | 12416 KB |
06_random04 | AC | 76 ms | 12416 KB |
06_random05 | AC | 65 ms | 12416 KB |
06_random06 | AC | 26 ms | 12416 KB |
06_random07 | AC | 74 ms | 12416 KB |
06_random08 | AC | 30 ms | 12416 KB |
06_random09 | AC | 148 ms | 12416 KB |
06_random10 | AC | 23 ms | 12416 KB |
06_random11 | AC | 61 ms | 12416 KB |
06_random12 | AC | 151 ms | 12416 KB |
06_random13 | AC | 33 ms | 12416 KB |
06_random14 | AC | 55 ms | 12416 KB |
06_random15 | AC | 17 ms | 12416 KB |
06_random16 | AC | 100 ms | 12416 KB |
06_random17 | AC | 56 ms | 12416 KB |
06_random18 | AC | 40 ms | 12416 KB |
06_random19 | AC | 36 ms | 12416 KB |