QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#307643#8005. Crossing the Bordervme50WA 62ms9224kbC++171.6kb2024-01-18 22:51:352024-01-18 22:51:35

Judging History

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

  • [2024-01-18 22:51:35]
  • 评测
  • 测评结果:WA
  • 用时:62ms
  • 内存:9224kb
  • [2024-01-18 22:51:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ctz __builtin_ctz
const int N=25,M=(1<<11)+5,MOD=998244353,INF=2e9;
int n,n1,n2,m,tp,a[N],b[N],s1[M],s2[M];
struct Node {int x,w;}z[M],z1[M],dp1[M],dp[M][M];vector<Node> z2[M];
void W(Node &x,Node y,int w=0)
{y.x+=w;if(x.x>y.x) x=y;else if(x.x==y.x) {x.w+=y.w;if(x.w>=MOD) x.w-=MOD;}}
int main()
{
	scanf("%d %d",&n,&m);n1=n/2;n2=n-n1;
	for(int i=0;i<n;++i) scanf("%d %d",&a[i],&b[i]);
	for(int i=0;i<1<<n1;++i) for(int j=0;j<1<<n2;++j)
		dp[i][j]=(Node) {INF,0};dp[0][0]=(Node) {0,1};
	for(int i=0;i<n;++i) for(int j=i;j<n-1;++j)
		if(b[i]<b[j]) swap(a[i],a[j]),swap(b[i],b[j]);
	for(int i=1;i<1<<n1;++i) s1[i]=s1[i&i-1]+a[ctz(i)];
	for(int i=1;i<1<<n2;++i) s2[i]=s2[i&i-1]+a[n1+ctz(i)];
	for(int i=0;i<1<<n2;++i)
	{
		for(int j=i;;j=i&j-1) {if(s2[j]<=m) z2[i].pb((Node) {j,s2[j]});if(!j) break;}
		sort(z2[i].begin(),z2[i].end(),[](Node x,Node y) {return x.w>y.w;});
	}
	for(int i=1,t;i<1<<n1;++i)
	{
		tp=0;
		for(int j=i;;j=i&j-(i&-i)*2)
		{if(s1[j]<=m) z1[++tp]=(Node) {j,s1[j]};if(j==(i&-i)) break;}
		sort(z1+1,z1+tp+1,[](Node x,Node y) {return x.w<y.w;});
		for(int j=0;j<1<<n2;++j)
		{
			t=1;Node t1=(Node) {INF,0};
			for(int k=1;k<=tp;++k) z[k]=dp[i^z1[k].x][j],z[k].x+=b[ctz(z1[k].x)];
			for(auto k:z2[j^(1<<n2)-1])
			{while(t<=tp && k.w+z1[t].w<=m) W(t1,z[t++]);W(dp[i][j|k.x],t1);}
		}
	}for(int i=0;i<1<<n2;++i) dp1[i^(1<<n2)-1]=dp[(1<<n1)-1][i];
	for(int i=(1<<n2)-1;i;--i) for(int j=i;;j=i&j-(i&-i)*2)
	{if(s2[j]<=m) W(dp1[i^j],dp1[i],b[n1+ctz(j)]);if(j==(i&-i)) break;}
	printf("%d %d\n",dp1[0].x,dp1[0].w);return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 4012kb

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: 62ms
memory: 9224kb

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:

8627232 4

result:

wrong answer 1st numbers differ - expected: '9391997', found: '8627232'