QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#287629#7754. Rolling For DaysMax_s_xaMWA 1ms3696kbC++144.1kb2023-12-20 20:44:152023-12-20 20:44:16

Judging History

你现在查看的是最新测评结果

  • [2023-12-20 20:44:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3696kb
  • [2023-12-20 20:44:15]
  • 提交

answer

#include <iostream>
#include <algorithm>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 1010, MAXM = (1 << 12) + 5, mod = 998244353;

int n, m, q, a[15], b[15];

int suma[MAXM], sumb[MAXM];
ll fac[MAXN], inv[MAXN], sinv[MAXN];
ll f[MAXN][MAXM], fs[MAXN][MAXM], g[MAXN][MAXM], gs[MAXN][MAXM];
inline ll C(int n, int m) {return fac[n] * inv[n - m] % mod * inv[m] % mod;}

int main()
{
    // freopen("I.in", "r", stdin);
    // freopen("I.out", "w", stdout);
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    fac[0] = fac[1] = inv[0] = inv[1] = 1;
    for (int i = 2; i < MAXN; i++) fac[i] = fac[i - 1] * i % mod, inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    sinv[1] = 1;
    for (int i = 2; i < MAXN; i++) sinv[i] = (sinv[i - 1] + inv[i]) % mod, inv[i] = inv[i - 1] * inv[i] % mod;
    Read(n), Read(m);
    for (int i = 1; i <= m; i++) Read(a[i]), suma[1 << i - 1] = a[i];
    for (int i = 1; i <= m; i++) Read(b[i]), sumb[1 << i - 1] = b[i], q += b[i];
    for (int s = 1; s < (1 << m); s++)
        suma[s] = suma[s ^ (s & -s)] + suma[s & -s], sumb[s] = sumb[s ^ (s & -s)] + sumb[s & -s];
        
    for (int i = 0; i <= q; i++) g[i][0] = inv[n];
    for (int s = 1; s < (1 << m); s++)
    {
        for (int i = 1; i <= q; i++)
        {
            if (i < sumb[s]) continue;
            for (int x = 1; x <= m; x++)
                if (s & (1 << x - 1))
                {
                    int ss = s ^ (1 << x - 1);
                    ll G = (gs[i - 1][ss] - g[i - 1][ss] * sinv[n - i - suma[ss] + sumb[ss]] % mod) * (suma[ss] - sumb[ss]) % mod;
                    ll P = C(i - sumb[ss] - 1, b[x] - 1) % mod * fac[a[x]] % mod * inv[a[x] - b[x]] % mod * fac[n - i - suma[ss] + sumb[ss]] % mod;
                    f[i][s] = (f[i][s] + (fs[i - 1][ss] + G) * P) % mod;
                    g[i][s] = (g[i][s] + g[i - 1][ss] * P) % mod;
                }
            fs[i][s] = (fs[i - 1][s] + f[i][s] * inv[n - i - suma[s] + sumb[s]]) % mod;
            gs[i][s] = (gs[i - 1][s] + g[i][s] * sinv[n - i - suma[s] + sumb[s]] % mod * inv[n - i - suma[s] + sumb[s]]) % mod;
            g[i][s] = (g[i - 1][s] + g[i][s] * inv[n - i - suma[s] + sumb[s]]) % mod;
        }
    }
    cout << (f[q][(1 << m) - 1] + mod + q) % mod << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 2
1 1
1 1

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3552kb

input:

4 2
2 2
2 1

output:

582309210

result:

ok answer is '582309210'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3696kb

input:

5 5
1 1 1 1 1
0 0 0 0 1

output:

1

result:

wrong answer expected '5', found '1'