QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#133730#4939. Red Black BallPhantomThreshold#WA 2ms4116kbC++203.2kb2023-08-02 13:36:492023-08-02 13:36:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 13:36:51]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4116kb
  • [2023-08-02 13:36:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

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=50;
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;
}

int 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 (int t=-lim;t<=lim;t++) dp[t]=dp[t]*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);
			}
			/*
			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: 4004kb

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: 3992kb

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: 4052kb

input:

2 3
1 RED
10 BLACK
7 4 2

output:

6

result:

ok single line: '6'

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 4116kb

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:

739852650

result:

wrong answer 1st lines differ - expected: '850819974', found: '739852650'