QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687899#8005. Crossing the BorderpeimudaRE 0ms0kbC++142.1kb2024-10-29 21:48:002024-10-29 21:48:01

Judging History

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

  • [2024-10-29 21:48:01]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-29 21:48:00]
  • 提交

answer

#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#define pr pair
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pll pr<ll,ll>
#define pii pr<int,int>
#define piii pr<int,pii>
using namespace std;
const ll m=998244353;
pii p[22];
pii dp[1<<22];
int w[22];
int c[22];
int ts[1<<22];
vector<pii> hl[1<<11];
vector<pii> hr[1<<11];
int gh[1<<11];
void operator+=(pii&a,pii b)
{
	if(a.f==b.f) a.s+=b.s,a.s%=m;
	else a=min(a,b);
}
pii operator+(pii a,pii b)
{
	if(a.f==b.f) return mp(a.f,(a.s+b.s)%m);
	return min(a,b);
}
pii operator+(pii a,int b)
{
	return mp(a.f+b,a.s);
}
int main()
{
	freopen("b.in","r",stdin);
	freopen("b.out","w",stdout);
	ios_base::sync_with_stdio(0);
	int n,lm;
	cin>>n>>lm;
	for(int i=0;i<n;i++) cin>>p[i].s>>p[i].f;
	sort(p,p+n);
	for(int i=0;i<1<<n;i++) dp[i]=mp(1500000000,0);
	dp[0]=mp(0,1);
	for(int i=0;i<n;i++) w[i]=p[i].s,c[i]=p[i].f;
	int hf=n/2,rs=n-hf;
	for(int i=1;i<1<<n;i++)
	{
		int lb=0;
		for(int j=0;j<n;j++) if(i&1<<j)
		{
			lb=j;
			break;
		}
		ts[i]=w[lb]+ts[i^1<<lb];
	}
	for(int i=1;i<1<<hf;i++)
	{
		int hg=0;
		for(int j=0;j<hf;j++) if(i&1<<j) hg=j;
		for(int k=i;k>0;k=(k-1)&i)
		{
			if((k&1<<hg)==0) continue;
			if(ts[k]<=lm) dp[i]+=dp[i^k]+c[hg];
		}
	}
	for(int i=0;i<1<<hf;i++)
	{
		for(int j=0;j<=i;j++) if((i&j)==j)
		{
			hl[i].push_back(mp(ts[j],j));
		}
		sort(hl[i].begin(),hl[i].end());
	}
	for(int i=1;i<1<<rs;i++)
	{
		int hg=0;
		for(int j=0;j<rs;j++) if(i&1<<j) hg=j;
		gh[i]=hg;
		for(int k=i;k>0;k=(k-1)&i)
		{
			if((k&1<<hg)==0) continue;
			hr[i].push_back(mp(ts[k<<hf],k<<hf));
		}
		sort(hr[i].begin(),hr[i].end());
	}
	for(int i=1<<hf;i<1<<n;i++)
	{
		vector<pii>&vl=hl[(~i)&((1<<hf)-1)],&vr=hr[i>>hf];
		int sx=vl.size(),sy=vr.size();
		int tr=0;
		pii su=mp(1500000000,0);
		for(int j=sx-1;j>=0;j--)
		{
			for(;tr<sy&&vr[tr].f+vl[j].f<=lm;tr++)
			{
				su+=dp[i^vr[tr].s];
			}
			dp[i|vl[j].s]+=su+c[gh[i>>hf]+hf];
		}
	}
	cout<<dp[(1<<n)-1].f<<' '<<dp[(1<<n)-1].s<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

5 5
3 5
1 4
2 3
2 2
2 1

output:


result: