QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#133783 | #4939. Red Black Ball | PhantomThreshold# | WA | 4ms | 5676kb | C++20 | 3.3kb | 2023-08-02 14:00:10 | 2023-08-02 14:00:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<ll,ll> pii;
const int maxn=100;
const ll INF=1e18;
const ll mod=998244353;
ll fac[maxn+50];
ll ifac[maxn+50];
ll ksm(ll a,ll x){
ll ret=1;
for (;x;x>>=1,a=a*a%mod) if (x&1) ret=ret*a%mod;
return ret;
}
void prepare(){
fac[0]=1;
for (int i=1;i<=maxn;i++) fac[i]=fac[i-1]*i % mod;
ifac[maxn]=ksm(fac[maxn],mod-2);
for (int i=maxn-1;i>=0;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}
inline ll C(ll n,ll m){
if (m<0 || m>n) return 0;
return fac[n]*ifac[m] % mod*ifac[n-m]%mod;
}
inline ll A(ll n,ll m){
if (m<0 || m>n) return 0;
return fac[n]*ifac[n-m]%mod;
}
int n,m;
pii a[maxn+50];
ll b[maxn+50];
const int lim=80;
inline ll& ref(vector<ll> &v,int x){
return v[x+lim];
}
vector<ll> rec[maxn+50][maxn+50];
bool vis[maxn+50][maxn+50];
vector<ll> solve(ll l,ll r,ll xl,ll xr,ll tp){
if (l>r){
vector<ll> ans(2*lim+1);
ref(ans,0)=1;
return ans;
}
if (vis[l][r]) return rec[l][r];
vector<ll> ans(2*lim+1);
for (int k=l;k<=r;k++){
if (xr-b[k]<b[k]-xl){
vector<ll> tmp=solve(l,k-1,xl,b[k],tp);
ll prod=A(r-l,r-k);
for (int i=-lim;i<=lim;i++){
int j=i+(r-k+1)*(-tp);
if (-lim<=j && j<=lim){
(ref(ans,j)+=prod*ref(tmp,i))%=mod;
}
}
}
else{
vector<ll> tmp=solve(k+1,r,b[k],xr,tp);
ll prod=A(r-l,k-l);
for (int i=-lim;i<=lim;i++){
int j=i+(k-l+1)*(tp);
if (-lim<=j && j<=lim){
(ref(ans,j)+=prod*ref(tmp,i))%=mod;
}
}
}
}
vis[l][r]=1;
rec[l][r]=ans;
/*
cout << l << " " << r << " " << xl << " " << xr << endl;
for (int i=-3;i<=3;i++) cout << ref(ans,i) << " ";
cout << endl;
*/
return ans;
}
signed main(){
prepare();
cin >> n >> m;
for (int i=1;i<=n;i++){
cin >> a[i].first;
string str;
cin >> str;
if (str[0]=='R') a[i].second=1;
}
for (int i=1;i<=m;i++) cin >> b[i];
sort(a+1,a+n+1);
sort(b+1,b+m+1);
a[0]=make_pair(-INF,a[1].second);
a[n+1]=make_pair(INF,a[n].second);
/*
for (int i=0;i<=10;i++) cout << a[i].first << " ";cout << endl;
for (int i=0;i<=10;i++) cout << a[i].second << " ";cout << endl;
for (int i=0;i<=10;i++) cout << b[i] << " ";cout << endl;
*/
vector<ll> dp(2*lim+1);
ref(dp,0)=1;
for (int i=1,l=1;i<=n+1;i++){
if (l>m) break;
if (a[i-1].first<=b[l] && b[l]<=a[i].first){
int r=l;
for (;r<=m && (a[i-1].first<=b[r] && b[r]<=a[i].first);) r++;
r--;
if (a[i-1].second==a[i].second){
ll prod=A(r,r-l+1)%mod;
for (auto &e:dp) e=e*prod % mod;
}
else{
vector<ll> now=solve(l,r,a[i-1].first,a[i].first,a[i-1].second-a[i].second);
vector<ll> tmp(2*lim+1);
for (int x=-lim;x<=lim;x++){
for (int y=-lim;y<=lim;y++){
if (-lim<=x+y && x+y<=lim){
(ref(tmp,x+y)+=ref(dp,x)*ref(now,y))%=mod;
}
}
}
dp.swap(tmp);
for (auto &e:dp) e=e*C(r,r-l+1)%mod;
}
/*
cout << "i : " << i << "\n";
cout << "l,r : " << l << " " << r << "\n";
*/
l=r+1;
}
else continue;
}
ll cnt=0;
for (int i=1;i<=n;i++) if (a[i].second) cnt++;else cnt--;
ll ans=0;
for (int i=-lim;i<=lim;i++){
if (cnt+i>0){
ans=(ans+ref(dp,i))%mod;
}
}
cout << ans << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4056kb
input:
2 3 1 BLACK 10 RED 2 5 7
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 2ms
memory: 4040kb
input:
2 3 1 RED 10 BLACK 2 4 7
output:
6
result:
ok single line: '6'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3988kb
input:
2 3 1 RED 10 BLACK 7 4 2
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 4176kb
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:
850819974
result:
ok single line: '850819974'
Test #5:
score: 0
Accepted
time: 2ms
memory: 4152kb
input:
24 46 1579 BLACK 10321 BLACK 7159 RED 13111 RED 11437 RED 277 BLACK 11623 BLACK 9391 RED 1765 RED 6787 BLACK 12367 BLACK 8647 RED 1207 RED 3811 RED 4183 BLACK 649 BLACK 11995 RED 6043 RED 2137 BLACK 8833 BLACK 7345 BLACK 463 RED 4369 RED 5113 BLACK 10507 7717 2509 4741 3997 5299 10879 8275 9763 5671...
output:
988708148
result:
ok single line: '988708148'
Test #6:
score: 0
Accepted
time: 3ms
memory: 5588kb
input:
2 49 747 RED 38197 BLACK 23966 11982 30707 20970 32205 23217 1496 24715 36699 20221 8986 8237 32954 29209 35950 18723 11233 13480 5990 22468 12731 27711 7488 2245 26213 16476 17225 34452 19472 15727 14978 9735 3743 4492 2994 33703 6739 17974 5241 21719 14229 28460 25464 29958 26962 35201 37448 10484...
output:
554620557
result:
ok single line: '554620557'
Test #7:
score: 0
Accepted
time: 3ms
memory: 4692kb
input:
5 49 18120 BLACK 7140 BLACK 39348 RED 552 RED 10068 RED 28368 2748 23244 10800 21780 34956 20316 15192 13728 6408 3480 22512 18852 2016 36420 4944 31296 37152 17388 7872 35688 32760 16656 34224 37884 19584 1284 11532 33492 26904 24708 15924 21048 4212 9336 5676 32028 29100 29832 23976 12996 27636 26...
output:
680298042
result:
ok single line: '680298042'
Test #8:
score: 0
Accepted
time: 0ms
memory: 4328kb
input:
13 49 107689803 BLACK 17641182 BLACK 719317410 RED 998074505 RED 629653125 BLACK 596623825 RED 302505396 BLACK 755371774 BLACK 894467843 BLACK 4346620 RED 67686851 RED 195025022 RED 843051518 RED 549024576 858137241 623250360 760797781 289351341 882742196 363095414 925898076 534873997 550178294 5220...
output:
48457350
result:
ok single line: '48457350'
Test #9:
score: 0
Accepted
time: 0ms
memory: 4216kb
input:
16 47 57366995 RED 142257512 RED 269104096 BLACK 85386190 BLACK 947963705 RED 327042464 RED 249359510 RED 779101020 BLACK 572804408 RED 14976978 BLACK 994513563 BLACK 12270136 RED 832385903 BLACK 827404778 RED 349299284 BLACK 157782755 BLACK 194509365 275027783 635585542 141178577 746922135 28144721...
output:
110578970
result:
ok single line: '110578970'
Test #10:
score: 0
Accepted
time: 0ms
memory: 4648kb
input:
4 47 557094997 BLACK 977689947 RED 524426310 RED 37970126 BLACK 490604903 841435598 941812205 445138440 510338155 186951281 171655969 622981900 583907196 970645377 428450182 138362981 621613180 99063603 462141100 154435607 547626426 298066536 620132019 171659177 777569078 731639638 947801880 4924222...
output:
371087856
result:
ok single line: '371087856'
Test #11:
score: 0
Accepted
time: 1ms
memory: 5616kb
input:
2 50 211 BLACK 160 RED 195 205 189 187 179 175 163 164 161 199 169 194 182 192 162 197 173 165 174 167 201 176 207 206 184 196 181 204 190 191 198 183 180 210 186 208 209 203 171 178 193 202 168 185 172 200 170 188 177 166
output:
502060921
result:
ok single line: '502060921'
Test #12:
score: 0
Accepted
time: 4ms
memory: 5676kb
input:
2 50 60 RED 9 BLACK 30 31 37 10 32 11 22 50 41 33 40 42 49 16 25 53 45 38 47 18 35 15 12 57 59 28 52 24 58 13 17 44 34 19 21 56 23 46 51 36 14 39 20 26 43 55 27 29 54 48
output:
912286572
result:
ok single line: '912286572'
Test #13:
score: 0
Accepted
time: 3ms
memory: 5564kb
input:
2 49 797 BLACK 847 RED 815 845 846 831 798 814 802 836 804 822 824 843 813 811 829 821 835 808 819 825 842 809 799 816 840 817 803 838 832 833 841 812 839 823 844 837 826 828 805 830 818 810 807 827 800 834 820 801 806
output:
98264595
result:
ok single line: '98264595'
Test #14:
score: -100
Wrong Answer
time: 1ms
memory: 4000kb
input:
4 10 1 RED 10 BLACK 20 RED 30 BLACK 2 4 7 11 15 19 22 27 31 35
output:
2116800
result:
wrong answer 1st lines differ - expected: '302400', found: '2116800'