QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#439541#8005. Crossing the BorderIDontKnowGoodNamesWA 91ms141092kbC++172.3kb2024-06-12 09:19:052024-06-12 09:19:06

Judging History

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

  • [2024-06-12 09:19:06]
  • 评测
  • 测评结果:WA
  • 用时:91ms
  • 内存:141092kb
  • [2024-06-12 09:19:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int NR=(1<<22)+10;
const int MOD=998244353;
int n,m,sum[NR],f[NR],g[NR],lg[NR];
struct task{
	int x,v;
	bool operator <(const task &T)const{
		return v<T.v;
	}
}t[30];
void add(int &x,int y){x=(x+y)%MOD;}
vector<int>buc[NR];
bool cmp1(int x,int y){return sum[x]<sum[y];}
bool cmp2(int x,int y){return sum[x]>sum[y];}
#define pb emplace_back

signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>t[i].x>>t[i].v;
	sort(t+1,t+1+n);
	for(int s=0;s<(1<<n);s++)
		for(int i=1;i<=n;i++)
			if((s>>(i-1))&1)sum[s]+=t[i].x;
	memset(f,999999,sizeof(f));
	int k=n/2,S1=(1<<k)-1,S2=(1<<n)-S1-1;
	for(int s=1;s<(1<<n);s++)lg[s]=lg[s>>1]+1;
	f[0]=0;g[0]=1;
	for(int s=0;s<=S1;s++){
		int tmp=S1^s;
		for(int lcy=tmp;;lcy=(lcy-1)&tmp)
			if(lcy>s){
				if(sum[lcy]<=m){
					if(f[s|lcy]>f[s]+t[lg[lcy]].v)
						f[s|lcy]=f[s]+t[lg[lcy]].v,g[s|lcy]=0;
					if(f[s|lcy]==f[s]+t[lg[lcy]].v)add(g[s|lcy],g[s]);
				}
				if(!lcy)break;
			}
			else break;
	}
	for(int s=0;s<=S2;s+=(1<<k)){
		int tmp=S1^s;
		for(int lcy=tmp;;lcy=(lcy-1)&tmp)
			if(lcy>s){
				if(sum[lcy]<=m){
					if(f[s|lcy]>f[s]+t[lg[lcy]].v)
						f[s|lcy]=f[s]+t[lg[lcy]].v,g[s|lcy]=0;
					if(f[s|lcy]==f[s]+t[lg[lcy]].v)add(g[s|lcy],g[s]);
				}
				if(!lcy)break;
			}
			else break;
	}
	for(int s=0;s<=S1;s++){
		for(int lcy=0;lcy<=s;lcy++)
			if((s|lcy)==s)buc[s].pb(lcy);
		sort(buc[s].begin(),buc[s].end(),cmp1);
	}
	for(int s=0;s<=S2;s+=(1<<k)){
		for(int lcy=0;lcy<=s;lcy+=(1<<k))
			if((s|lcy)==s)buc[s].pb(lcy);
		sort(buc[s].begin(),buc[s].end(),cmp2);
	}
	for(int s=0;s<(1<<n);s++)
		f[s]=f[s&S1]+f[s&S2],g[s]=g[s&S1]*g[s&S2]%MOD;
	for(int s=0;s<(1<<n);s++){
		int tmp2=S2^(s&S2),tmp1=s&S1;
		if(!tmp2||!tmp1)continue;
		int now=0,len=buc[tmp1].size(),minv=1e18,minc=0;
		for(int lcy:buc[tmp2])
			if(lcy*2>tmp2){
				while(now<len&&sum[buc[tmp1][now]]+sum[lcy]<=m){
					int tmp=(tmp1^buc[tmp1][now])|(s&S2);
					if(minv>f[tmp])minv=f[tmp],minc=0;
					if(minv==f[tmp])add(minc,g[tmp]);
					now++;
				}
				if(f[s|lcy]>minv+t[lg[lcy]].v)f[s|lcy]=minv+t[lg[lcy]].v,g[s|lcy]=0;
				if(f[s|lcy]==minv+t[lg[lcy]].v)add(g[s|lcy],minc);
			}
	}
	cout<<f[(1<<n)-1]<<" "<<g[(1<<n)-1]<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 16ms
memory: 134712kb

input:

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

output:

9 4

result:

ok 2 number(s): "9 4"

Test #2:

score: -100
Wrong Answer
time: 91ms
memory: 141092kb

input:

18 10000000
956231 904623
1692946 1796774
1081323 1170319
3218792 2542661
3183376 3037270
1869132 1442561
35436 35018
1564635 1939950
1847344 2006043
755870 899310
1671882 2057413
1369264 1338951
3132483 3504034
2056224 1825640
1840949 1562071
1514040 1405352
2300821 2421801
2466540 3004920

output:

9391997 140

result:

wrong answer 2nd numbers differ - expected: '70', found: '140'