Submission #3913968


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }
template<typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template<typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == 0) {
        v.clear();
        return 0;
    }
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}


vector<vll> f;

void f_init(int nmax=1000, int kmax=1000){
    f.resize(1+nmax);
    for (int n=0; n<=nmax; ++n) {
        f[n].resize(1+kmax);
        f[n][0] = (n == 0) ? 1 : 0;
        for (int k=1; k<=kmax; ++k) {
            f[n][k] = ADD(f[n][k-1], ((0 <= n-k) ? f[n-k][k] : 0));
        }
    }
}

ll sub(int total, vi& groups) {
    int G = groups.size();
    vll dp(total+1, 0), dp2(total+1);
    dp[0] = 1;
    for (int g: groups) {
        dp2.assign(total+1, 0);
        for (int i=0; i<=total; ++i) {
            for (int j=i; j<=total; ++j) {
                dp2[j] = ADD(dp2[j], MUL(dp[i], f[j-i][g]));
            }
        }
        swap(dp,dp2);
    }
    return dp[total];
}

ll solve(int N, int M, vi& killA, vi& killB) {
    int sumA = accumulate(ALL(killA), 0);
    int sumB = accumulate(ALL(killB), 0);

    f_init(max(sumA, sumB), max(killA.size(), killB.size()));

    map<int,int> stA, stB;
    for(int k:killA) stA[k]++;
    for(int k:killB) stB[k]++;
    vi gA, gB;
    for(ii p: stA) gA.pb(p.second);
    for(ii p: stB) gB.pb(p.second);
    sort(ALL(gA));
    sort(ALL(gB));

    return MUL( sub(sumB, gA), sub(sumA, gB) );
}

int main() {
    int N, M; scanf("%d%d", &N, &M); read_cr();
    vi killA(N), killB(M);
    loadvec(killA, N);
    loadvec(killB, M);
    cout << solve(N,M,killA,killB) << endl;
    return 0;
}

Submission Info

Submission Time
Task C - Kill/Death
User naoya_t
Language C++14 (GCC 5.4.1)
Score 500
Code Size 4441 Byte
Status
Exec Time 162 ms
Memory 1024 KB

Compile Error

./Main.cpp: In function ‘void read_cr()’:
./Main.cpp:95:28: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
     fgets(_buf, 256, stdin);
                            ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:147:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     int N, M; scanf("%d%d", &N, &M); read_cr();
                                    ^

Test Cases

Set Name Score / Max Score Test Cases
All 500 / 500 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 1 ms 256 KB
01_sample01 1 ms 256 KB
01_sample02 1 ms 256 KB
01_sample03 1 ms 256 KB
01_sample04 2 ms 256 KB
02_minimal00 1 ms 256 KB
02_minimal01 3 ms 256 KB
02_minimal02 3 ms 256 KB
02_minimal03 5 ms 256 KB
03_maximal00 11 ms 1024 KB
03_maximal01 7 ms 1024 KB
04_random-easy00 1 ms 256 KB
04_random-easy01 1 ms 256 KB
04_random-easy02 1 ms 256 KB
04_random-easy03 1 ms 256 KB
04_random-easy04 1 ms 256 KB
04_random-easy05 1 ms 256 KB
04_random-easy06 1 ms 256 KB
04_random-easy07 1 ms 256 KB
04_random-easy08 1 ms 256 KB
04_random-easy09 1 ms 256 KB
04_random-easy10 1 ms 256 KB
04_random-easy11 1 ms 256 KB
04_random-easy12 1 ms 256 KB
04_random-easy13 1 ms 256 KB
04_random-easy14 1 ms 256 KB
04_random-easy15 1 ms 256 KB
04_random-easy16 1 ms 256 KB
04_random-easy17 1 ms 256 KB
04_random-easy18 1 ms 256 KB
04_random-easy19 1 ms 256 KB
05_random-large00 113 ms 1024 KB
05_random-large01 162 ms 1024 KB
05_random-large02 125 ms 1024 KB
05_random-large03 115 ms 1024 KB
05_random-large04 118 ms 1024 KB
05_random-large05 127 ms 1024 KB
05_random-large06 128 ms 1024 KB
05_random-large07 123 ms 1024 KB
05_random-large08 119 ms 1024 KB
05_random-large09 115 ms 1024 KB
05_random-large10 118 ms 1024 KB
05_random-large11 119 ms 1024 KB
05_random-large12 124 ms 1024 KB
05_random-large13 127 ms 1024 KB
05_random-large14 125 ms 1024 KB
05_random-large15 107 ms 1024 KB
05_random-large16 122 ms 1024 KB
05_random-large17 130 ms 1024 KB
05_random-large18 123 ms 1024 KB
05_random-large19 115 ms 1024 KB
06_random00 54 ms 768 KB
06_random01 2 ms 384 KB
06_random02 5 ms 640 KB
06_random03 70 ms 512 KB
06_random04 25 ms 768 KB
06_random05 31 ms 640 KB
06_random06 10 ms 640 KB
06_random07 22 ms 640 KB
06_random08 11 ms 384 KB
06_random09 70 ms 512 KB
06_random10 5 ms 768 KB
06_random11 21 ms 512 KB
06_random12 65 ms 512 KB
06_random13 15 ms 384 KB
06_random14 20 ms 640 KB
06_random15 2 ms 256 KB
06_random16 36 ms 896 KB
06_random17 22 ms 640 KB
06_random18 11 ms 768 KB
06_random19 13 ms 512 KB