Submission #3026467


Source Code Expand

#include <bits/stdc++.h>
#define MAX 1000000
#define MOD 1000000007
using namespace std;
typedef long long ll;

int N, M;
map<ll, ll> A, B;
vector<vector<ll>> dp(100001, vector<ll>(101, 0));

ll p(ll n, ll k){
    
    if(k == 0) return !n;
    
    ll& res = dp[n][k];
    if(res) return res;
    
    res += p(n, k - 1);
    res %= MOD;
    res += (n < k) ? 0 : p(n - k, k);
    res %= MOD;
    
    return res;
}

ll solve(ll sum, map<ll, ll> mp){
    
    vector<ll> v(1001, 0);
    vector<ll> w(1001, 0);
    v[sum] = 1;
    
    for(auto m : mp){
        ll x = m.second;
        fill(w.begin(), w.end(), 0);
        
        for(int i = 0; i <= sum; ++i){
            if(v[i]){
                for(int j = 0; j <= i; ++j){
                    (w[i - j] += v[i] * p(j, x)) %= MOD;
                }
            }
        }
        swap(v, w);
    }
    return v[0];
}

int main(void){
    
    cin >> N >> M;
    ll asum = 0, bsum = 0;
    for(int i = 0; i < N; ++i){
        int temp; cin >> temp;
        asum += temp, ++A[temp];
    }
    for(int i = 0; i < M; ++i){
        int temp; cin >> temp;
        bsum += temp, ++B[temp];
    }
    
    ll aans = solve(bsum, A);
    ll bans = solve(asum, B);
    
    cout << (aans * bans) % MOD << endl;
    
    return 0;
}

Submission Info

Submission Time
Task C - Kill/Death
User sgneet
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1343 Byte
Status AC
Exec Time 236 ms
Memory 82304 KB

Judge Result

Set Name All
Score / Max Score 500 / 500
Status
AC × 71
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 51 ms 82304 KB
01_sample01 AC 51 ms 82304 KB
01_sample02 AC 51 ms 82304 KB
01_sample03 AC 51 ms 82304 KB
01_sample04 AC 51 ms 82304 KB
02_minimal00 AC 51 ms 82304 KB
02_minimal01 AC 52 ms 82304 KB
02_minimal02 AC 51 ms 82304 KB
02_minimal03 AC 51 ms 82304 KB
03_maximal00 AC 58 ms 82304 KB
03_maximal01 AC 53 ms 82304 KB
04_random-easy00 AC 51 ms 82304 KB
04_random-easy01 AC 51 ms 82304 KB
04_random-easy02 AC 51 ms 82304 KB
04_random-easy03 AC 51 ms 82304 KB
04_random-easy04 AC 51 ms 82304 KB
04_random-easy05 AC 51 ms 82304 KB
04_random-easy06 AC 52 ms 82304 KB
04_random-easy07 AC 51 ms 82304 KB
04_random-easy08 AC 51 ms 82304 KB
04_random-easy09 AC 51 ms 82304 KB
04_random-easy10 AC 51 ms 82304 KB
04_random-easy11 AC 51 ms 82304 KB
04_random-easy12 AC 51 ms 82304 KB
04_random-easy13 AC 51 ms 82304 KB
04_random-easy14 AC 51 ms 82304 KB
04_random-easy15 AC 51 ms 82304 KB
04_random-easy16 AC 51 ms 82304 KB
04_random-easy17 AC 52 ms 82304 KB
04_random-easy18 AC 52 ms 82304 KB
04_random-easy19 AC 52 ms 82304 KB
05_random-large00 AC 185 ms 82304 KB
05_random-large01 AC 214 ms 82304 KB
05_random-large02 AC 200 ms 82304 KB
05_random-large03 AC 187 ms 82304 KB
05_random-large04 AC 191 ms 82304 KB
05_random-large05 AC 236 ms 82304 KB
05_random-large06 AC 198 ms 82304 KB
05_random-large07 AC 197 ms 82304 KB
05_random-large08 AC 193 ms 82304 KB
05_random-large09 AC 187 ms 82304 KB
05_random-large10 AC 190 ms 82304 KB
05_random-large11 AC 192 ms 82304 KB
05_random-large12 AC 197 ms 82304 KB
05_random-large13 AC 202 ms 82304 KB
05_random-large14 AC 198 ms 82304 KB
05_random-large15 AC 177 ms 82304 KB
05_random-large16 AC 197 ms 82304 KB
05_random-large17 AC 204 ms 82304 KB
05_random-large18 AC 199 ms 82304 KB
05_random-large19 AC 187 ms 82304 KB
06_random00 AC 115 ms 82304 KB
06_random01 AC 52 ms 82304 KB
06_random02 AC 54 ms 82304 KB
06_random03 AC 132 ms 82304 KB
06_random04 AC 78 ms 82304 KB
06_random05 AC 85 ms 82304 KB
06_random06 AC 61 ms 82304 KB
06_random07 AC 74 ms 82304 KB
06_random08 AC 62 ms 82304 KB
06_random09 AC 127 ms 82304 KB
06_random10 AC 54 ms 82304 KB
06_random11 AC 72 ms 82304 KB
06_random12 AC 130 ms 82304 KB
06_random13 AC 69 ms 82304 KB
06_random14 AC 73 ms 82304 KB
06_random15 AC 51 ms 82304 KB
06_random16 AC 93 ms 82304 KB
06_random17 AC 76 ms 82304 KB
06_random18 AC 62 ms 82304 KB
06_random19 AC 67 ms 82304 KB