QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#133673 | #4939. Red Black Ball | Delay_for_five_minutes# | WA | 1ms | 3684kb | C++14 | 5.4kb | 2023-08-02 12:48:18 | 2023-08-02 12:48:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n , m;
typedef long long ll;
vector<pair<int,int> > v;
typedef vector<int> poly;
const int mod = 998244353;
int c[105][105];
int t[105];
poly operator* (poly a,poly b)
{
poly C(a.size() + b.size() - 1);
for(int i = 0;i < a.size();i++) {
for(int j = 0;j < b.size();j++) {
C[i + j] = (C[i + j] + 1LL*a[i]*b[j]) % mod;
}
}
return C;
}
poly operator+ (poly a,poly b)
{
if(a.size() < b.size()) a.resize(b.size());
for(int i = 0;i < a.size() && i < b.size();i++) a[i] = (a[i] + b[i]) % mod;
return a;
}
inline int C(int a,int b)
{
return c[a][b];
}
poly solve(int l,int r)
{
// printf("sol %d %d\n",l,r);
if(r - l + 1 <= 2) {
poly p(1) ; p[0] = 1;
return p;
}
poly dp[55][55][2];
int len = r - l + 1;
for(int i = len;i >= 1;i--) {
for(int j = i;j <= len;j++) {
for(int u = 0;u < 2;u++){
if(i == j || i + 1 == j) {
dp[i][j][u].resize(1) ; dp[i][j][u][0] = 1;
}
else {
for(int k = i + 1;k < j;k++) {
poly L , R;
if(v[k+l-1].first - v[i+l-1].first <= v[j+l-1].first - v[k+l-1].first) {
L.resize(k - i) ;
if(u == 0) L[k - i - 1] = t[k - i - 1];
else L[0] = t[k - i - 1];
auto w = L * dp[k][j][u];
for(auto &x : w) x = 1LL*x*C(j - i - 2 , k - i - 1) % mod;
w.resize(w.size() + 1);
if(u == 0) {
for(int i = w.size() - 1;i >= 1;i--) w[i] = w[i - 1];
w[0] = 0;
}
/*if(i == 1 && j == 5) {
printf("K %d , %d ",k , t[k - i - 1]);
for(auto x : w) printf("%d ",x);
printf("\n");
}*/
dp[i][j][u] = dp[i][j][u] + w;
}
else {
R.resize(j - k);
if(u == 1) R[j - k - 1] = t[j - k - 1];
else R[0] = t[j - k - 1];
auto w = dp[i][k ][u] * R;
for(auto &x : w) x = 1LL*x*C(j - i - 2 , k - i - 1) % mod;
w.resize(w.size() + 1);
if(u == 1) {
for(int i = w.size() - 1;i >= 1;i--) w[i] = w[i - 1];
w[0] = 0;
}
/* if(i == 1 && j == 5) {
printf("K %d , ",k);
for(auto x : w) printf("%d ",x);
printf("\n");
}*/
dp[i][j][u] = dp[i][j][u] + w;
}
}
}
/* printf("%d %d %d : ",i,j,u);
for(auto x : dp[i][j][u]) printf("%d ",x);
printf("\n");*/
}
}
}
return dp[1][len][v[l].second];
}
int main()
{
// freopen("in.txt","r",stdin);
ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
cin >> n >> m;
for(int i = 1;i <= n;i++) {
int x;
string s;cin >>x >> s;
if(s == "RED") v.push_back(pair<int,int>{x , 0});
else v.push_back(pair<int,int>{x , 1});
}
c[0][0] = 1; t[0] = 1;
for(int i = 1;i <= n + m;i++) {
c[i][0] = 1; t[i] = 1LL*t[i - 1]*i % mod;
for(int j = 1;j <= i;j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
}
for(int i = 1;i <= m;i++) {
int x;cin >> x;v.push_back(pair<int,int>{x , -1});
}
sort(v.begin() , v.end());
int lst =-1;
poly ans(1) ; ans[0] = 1;
int d = (n + m + 1) / 2;
for(int i = 0;i <= v.size();i++) {
if(i == v.size() || v[i].second != -1) {
if(v[i].second == 0) d--;
if(lst == -1 || i == v.size()) {
int num = i - lst - 1;
poly p(num + 1) ;
int u = (i == v.size() ? v[lst].second : v[i].second);
if(u == 0) p[num] = t[num];
else p[0] = t[num];
lst = i;
int x = ans.size() - 1 , y = p.size() - 1;
// printf("C %d , %d %d\n",c[x + y][x],x,y);
ans = ans * p;
for(auto &i : ans) i = 1LL*i*c[x+y][x] % mod;
}
else {
int num = i - lst - 1;
poly p;
if(v[i].second == v[lst].second){
p.resize(num + 1) ;
if(v[i].second == 0) p[num] = t[num];
else p[0] = t[num];
}
else {
p = solve(lst , i );
}
int x = ans.size() - 1 , y = p.size() - 1;
// printf("C %d , %d %d\n",c[x + y][x],x,y);
ans = ans * p;
for(auto &i : ans) i = 1LL*i*c[x+y][x] % mod;
lst = i;
}
}
}
int sol = 0;
// cout << d << '\n';
for(int i = max(0,d);i < ans.size();i++) sol = (sol + ans[i]) % mod;
cout << sol ;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3624kb
input:
2 3 1 BLACK 10 RED 2 5 7
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
2 3 1 RED 10 BLACK 2 4 7
output:
6
result:
ok single line: '6'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
2 3 1 RED 10 BLACK 7 4 2
output:
6
result:
ok single line: '6'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3652kb
input:
20 46 238846592 BLACK 199923217 RED 526626128 BLACK 62308338 RED 523811748 RED 59432 BLACK 273113193 BLACK 730729301 BLACK 973259012 RED 225318015 BLACK 611574923 RED 234880345 RED 485448383 BLACK 405607946 BLACK 747693124 RED 794086621 BLACK 91585417 BLACK 466451303 RED 244184598 RED 334788273 RED ...
output:
317190527
result:
wrong answer 1st lines differ - expected: '850819974', found: '317190527'