QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#411305#7754. Rolling For DaysSamponYWWA 1ms6080kbC++142.3kb2024-05-15 11:26:462024-05-15 11:26:47

Judging History

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

  • [2024-05-15 11:26:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6080kb
  • [2024-05-15 11:26:46]
  • 提交

answer

#include <bits/stdc++.h>
#define db double
#define il inline
#define re register
#define ll long long
#define ui unsigned
#define ull ui ll
#define i128 __int128
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define mems(v, x) memset(v, x, sizeof(v))
#define memc(a, b) memcpy(a, b, sizeof(a))
#define FOR(i, L, R) for(re int i = (L); i <= (R); ++i)
#define ROF(i, R, L) for(re int i = (R); i >= (L); --i)
#define LS i << 1, l, mid
#define RS i << 1 | 1, mid + 1, r
#define popc(x) __builtin_popcount(x)
using namespace std;
#define N 1005
#define M (1 << 12)
#define P 998244353
il int add(int x, int y) {return x + y < P ? x + y : x + y - P;}
il void addr(int &x, int y) {(x += y) >= P && (x -= P);}
il int qpow(int p, int n = P - 2) {
  int s = 1;
  while(n) {
    if(n & 1) s = 1ll * s * p % P;
    p = 1ll * p * p % P, n >>= 1;
  }
  return s;
}
int n, m, a[N], b[N];
int dp[N][M], f[N][M];
int C[N][N], fac[N];
int s[M], sum[M];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  FOR(i, 0, m - 1) cin >> a[i];
  FOR(i, 0, m - 1) cin >> b[i];
  fac[0] = 1; FOR(i, 1, n) fac[i] = 1ll * fac[i - 1] * i % P;
  int A = (1 << m) - 1;
  FOR(S, 1, A) {
    int x = __lg(S), T = S ^ (1 << x);
    s[S] = s[T] + a[x] - b[x], sum[S] = sum[T] + b[x];
  }
  FOR(i, 0, sum[A]) {
    C[i][0] = 1;
    FOR(j, 1, i) C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
  }
  int AL = 0;
  FOR(i, 0, m - 1) if(!b[i]) AL |= 1 << i;
  f[0][AL] = 1;
  FOR(i, 1, sum[A]) FOR(S, 0, A) {
    if(n - (i - 1) <= s[S]) continue;
    int p = qpow((n - (i - 1)) - s[S]), v = 1ll * (n - (i - 1)) * p % P;
    addr(f[i][S], 1ll * f[i - 1][S] * p % P);
    addr(dp[i][S], 1ll * p * add(dp[i - 1][S], 1ll * v * f[i - 1][S] % P) % P);
    if(i - 1 < sum[S]) continue;
    FOR(x, 0, m - 1) if(!(S >> x & 1)) {
      int T = S | (1 << x);
      int c = 1ll * C[a[x]][b[x]] * fac[b[x]] % P * C[(i - 1) - sum[S]][b[x] - 1] % P;
      addr(f[i][T], 1ll * f[i - 1][S] * p % P * c % P);
      addr(dp[i][T], 1ll * p * c % P * add(dp[i - 1][S], 1ll * v * f[i - 1][S] % P) % P);
    }
  }
  cout << dp[sum[A]][A];
  cerr << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 6028kb

input:

2 2
1 1
1 1

output:

2

result:

ok answer is '2'

Test #2:

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

input:

4 2
2 2
2 1

output:

582309210

result:

ok answer is '582309210'

Test #3:

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

input:

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

output:

5

result:

ok answer is '5'

Test #4:

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

input:

4 4
1 1 1 1
1 1 1 0

output:

831870299

result:

ok answer is '831870299'

Test #5:

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

input:

5 2
4 1
2 1

output:

0

result:

wrong answer expected '598946616', found '0'