QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#350943#7063. Space StationRong7WA 204ms17376kbC++142.7kb2024-03-11 10:22:502024-03-11 10:22:50

Judging History

This is the latest submission verdict.

  • [2024-03-11 10:22:50]
  • Judged
  • Verdict: WA
  • Time: 204ms
  • Memory: 17376kb
  • [2024-03-11 10:22:50]
  • Submitted

answer

// Not afraid to dark.

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

#define int long long

namespace io {
    int read_pos, read_dt; char read_char;
    inline int read (int &p = read_pos){
        p = 0, read_dt = 1; read_char = getchar ();
        while (! isdigit (read_char)){
            if (read_char == '-')
                read_dt = - 1;
            read_char = getchar ();
        }
        while (isdigit (read_char)){
            p = (p << 1) + (p << 3) + read_char - 48;
            read_char = getchar ();
        }
        return p = p * read_dt;
    }
    int write_sta[65], write_top;
    inline void write (int x){
        if (x < 0)
            putchar ('-'), x = - x;
        write_top = 0;
        do
            write_sta[write_top ++] = x % 10, x /= 10;
        while (x);
        while (write_top)
            putchar (write_sta[-- write_top] + 48);
    }
    int llen;
    inline int get_string (char c[], int &len = llen){
        len = 0;
        read_char = getchar ();
        while (read_char == ' ' || read_char == '\n' || read_char == '\r')
            read_char = getchar ();
        while (read_char != ' ' && read_char != '\n' && read_char != '\r'){
            c[++ len] = read_char;
            read_char = getchar ();
        }
        return len;
    }
}

const int N = 1e5, V = 50, mod = 1e9 + 7;
const unsigned long long sed = 37;
int n, ia, ct[V + 5], ans, jc[N + 5], inv[N + 5], inj[N + 5], sum;

vector < int > ac;
unordered_map < unsigned long long , int > mp;

inline unsigned long long Upload (vector < int > &a){
    unsigned long long res = 0;
    for (int i = V;i >= 1;-- i)
        res = res * sed + a[i];
    return res;
}

inline int Solve (int rest, int sum){
    if (rest == 0)
        return 1;
    if (sum >= V)
        return jc[rest];
    unsigned long long Hash = Upload (ac);
    if (mp.count (Hash))
        return mp[Hash];
    for (int i = 1;i <= sum;++ i)
        if (ac[i] < ct[i]){
            ++ ac[i];
            mp[Hash] += Solve (rest - 1, sum + i) * (ct[i] - ac[i] + 1) % mod;
            -- ac[i];
        }
    mp[Hash] %= mod;
    return mp[Hash];
}

signed main (){
    io::read (n), io::read (ia);
    sum += ia;
    for (int i = 1, a;i <= n;++ i){
        ++ ct[io::read (a)];
        sum += a;
    }
    inv[1] = jc[0] = jc[1] = inj[0] = inj[1] = 1;
    for (int i = 2;i <= n;++ i){
        inv[i] = 1ll * inv[i - mod % i] * (mod / i + 1) % mod;
        inj[i] = 1ll * inj[i - 1] * inv[i] % mod;
        jc[i] = 1ll * jc[i - 1] * i % mod;
    }
    ac.resize (V + 1, 0);
    io::write (1ll * Solve (n - ct[0], ia) * jc[n] % mod * inj[n - ct[0]] % mod), puts ("");
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5640kb

input:

3
2 1 2 3

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

5
1 1 1 1 2 3

output:

54

result:

ok single line: '54'

Test #3:

score: 0
Accepted
time: 3ms
memory: 5936kb

input:

100000
47 25 43 22 17 6 15 17 45 4 14 34 46 22 0 8 2 48 41 6 49 42 21 25 48 43 2 17 27 25 38 31 39 48 13 49 24 30 36 19 29 47 48 1 4 5 12 9 21 39 30 21 8 4 9 45 18 0 3 29 26 18 24 39 31 49 22 4 46 21 27 11 11 7 8 3 26 25 29 4 1 21 34 4 44 39 13 26 33 44 5 17 10 32 37 25 44 34 17 14 40 32 27 39 41 6 ...

output:

268605493

result:

ok single line: '268605493'

Test #4:

score: 0
Accepted
time: 3ms
memory: 5956kb

input:

100000
35 39 20 34 18 5 21 21 45 38 48 44 50 42 35 23 21 18 24 9 40 18 16 20 41 27 25 4 0 5 9 7 39 26 47 13 18 27 43 45 31 20 45 39 7 29 4 41 6 39 4 27 7 24 42 10 49 21 9 21 33 12 7 2 24 13 47 11 43 25 8 18 5 14 44 9 14 50 50 19 6 18 45 41 0 27 20 44 17 19 5 26 38 19 1 30 10 32 46 4 24 27 28 32 27 3...

output:

590621358

result:

ok single line: '590621358'

Test #5:

score: 0
Accepted
time: 10ms
memory: 6508kb

input:

100000
21 4 24 20 20 30 50 25 47 22 31 30 2 37 43 13 16 12 8 39 31 18 10 42 32 10 49 17 46 35 5 36 13 4 32 4 12 22 49 44 6 18 40 24 34 4 48 22 15 10 1 31 30 44 49 24 29 16 39 11 13 31 42 39 17 28 20 18 15 30 40 23 49 45 3 15 2 24 21 34 11 15 5 2 7 17 27 11 2 44 31 38 16 32 17 9 2 30 49 18 35 46 30 5...

output:

983292446

result:

ok single line: '983292446'

Test #6:

score: -100
Wrong Answer
time: 204ms
memory: 17376kb

input:

100000
7 20 29 6 48 4 29 30 48 7 16 15 7 7 26 28 38 32 42 43 47 19 4 37 25 21 21 3 43 13 2 38 14 34 40 19 7 18 5 43 33 16 36 11 35 30 15 2 25 10 49 9 2 40 31 40 9 36 19 28 19 23 26 27 10 18 45 24 38 35 48 6 42 27 13 22 16 50 17 25 42 10 16 15 41 30 6 31 36 17 31 49 18 18 33 14 19 5 27 7 19 15 32 43 ...

output:

360851090

result:

wrong answer 1st lines differ - expected: '363626098', found: '360851090'