QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#133779 | #4939. Red Black Ball | BoulevardDust# | WA | 1ms | 3516kb | C++17 | 2.4kb | 2023-08-02 13:59:41 | 2023-08-02 13:59:41 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <map>
#define p 998244353
#define mn 105
using namespace std;
int n, m, N, mxp, cnt[2], fac[mn], inv[mn], f[mn][mn];
vector<pair<int, int> > a;
int Pow(int a, int b) {
int ans = 1;
for(; b; b & 1 ? ans = 1ll * ans * a % p : 0, a = 1ll * a * a % p, b >>= 1);
return ans;
}
int C(int n, int m) {
if(n < 0 || m < 0 || n < m) return 0;
return 1ll * fac[n] * inv[m] % p * inv[n - m] % p;
}
void Inc(int &a, int b) {
if((a += b) >= p) a -= p;
}
int g(int l, int r, int k, int tl, int tr, int pl, int pr) {
if(l > r) return 1;
int res = 0, t = tl;
for(int i = l; i <= r; ++i) {
if(abs(a[i].first - pr) < abs(a[i].first - pl)) {
t = tr;
}
if(t == 1) {
for(int kk = 0; kk <= k; ++kk) {
Inc(res, 1ll * g(l, i - 1, kk, tl, t, pl, a[i].first) * g(i + 1, r, k - kk, t, tr, a[i].first, pr) % p * C(k, kk) % p);
}
}
else {
for(int kk = 0; kk <= k - 1; ++kk) {
Inc(res, 1ll * g(l, i - 1, kk, tl, t, pl, a[i].first) * g(i + 1, r, k - 1 - kk, t, tr, a[i].first, pr) % p * C(k - 1, kk) % p);
}
}
}
return res;
}
int main() {
cin >> n >> m;
N = n + m;
fac[0] = 1;
for(int i = 1; i <= N; ++i) {
fac[i] = 1ll * fac[i - 1] * i % p;
}
inv[N] = Pow(fac[N], p - 2);
for(int i = N - 1; i >= 0; --i) {
inv[i] = 1ll * inv[i + 1] * (i + 1) % p;
}
for(int i = 1; i <= n; ++i) {
int x;
string s;
cin >> x >> s;
int t = s == "BLACK";
++cnt[t];
a.push_back(make_pair(x, t));
mxp = max(mxp, x);
}
sort(a.begin(), a.end());
a.push_back(make_pair(0, a[0].second));
int tt = a[(int)a.size() - 1].second;
for(int i = 1; i <= m; ++i) {
int x;
cin >> x;
a.push_back(make_pair(x, 2));
mxp = max(mxp, x);
}
a.push_back(make_pair(mxp + 1, tt));
sort(a.begin(), a.end());
f[0][0] = 1;
int pre = 0;
for(int i = 1; i < (int)a.size(); ++i) if(a[i].second < 2) {
for(int j = 0; j <= n + m; ++j) {
for(int k = 0; k <= j; ++k) {
Inc(f[i][j], 1ll * f[i - 1][j - k] * g(pre + 1, i - 1, k, a[pre].second, a[i].second, a[pre].first, a[i].first) % p * C(j, k) % p);
}
}
pre = i;
}
int ans = 0;
for(int i = 0; i <= n + m; ++i) {
if(i + cnt[0] > n + m - i - cnt[0]) {
Inc(ans, f[(int)a.size() - 1][i]);
}
}
cout << ans << endl;
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3516kb
input:
2 3 1 BLACK 10 RED 2 5 7
output:
0
result:
wrong answer 1st lines differ - expected: '3', found: '0'