QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#465990#8005. Crossing the Borderucup-team052Compile Error//C++234.6kb2024-07-07 14:31:302024-07-07 14:31:31

Judging History

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

  • [2024-07-07 14:31:31]
  • 评测
  • [2024-07-07 14:31:30]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
inline int add(int x,int y) {return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z) {return add(add(x,y),z);}
inline int sub(int x,int y) {return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y) {return 1LL*x*y%mod;}
inline int mul(int x,int y,int z) {return mul(mul(x,y),z);}
#define inc(x,y) x+=y
#define dec(x,y) x=sub(x,y)
#define N 20
struct Node
{
	int w,c;
};
Node a[N+2];
bool cmp(Node x,Node y) {return x.c<y.c;}
int n,W,mn[1<<N],cnt[1<<N];
int sum[1<<N];
void bf()
{
	sort(a,a+n,cmp);
	for(int i=1;i<1<<n;i++)
	{
		int u=__builtin_ctz(i);
		sum[i]=sum[i^(1<<u)]+a[u].w;
	}
	mn[0]=0,cnt[0]=1;
	int ful=(1<<n)-1;
	for(int i=1;i<1<<n;i++)
	{
		mn[i]=inf;
		int u=31-__builtin_clz(i);
		for(int st=i;st>=(1<<u);st=i&(st-1))
		{
			if(sum[st]<=W)
			{
				if(mn[i^st]+a[u].c<mn[i]) mn[i]=mn[i^st]+a[u].c,cnt[i]=0;
				if(mn[i^st]+a[u].c==mn[i]) inc(cnt[i],cnt[i^st]);
			}
		}
	}
	printf("%d %d\n",mn[ful],cnt[ful]);
}
int l=20;
void fwt(int *f){
	for(int i=1;i<(1<<l);i<<=1)for(int j=0;j<(1<<l);j+=i<<1)for(int k=0;k<i;++k){
		f[i+j+k]=add(f[i+j+k],f[j+k]);
	}
}
void ifwt(int *f){
	for(int i=1;i<(1<<l);i<<=1)for(int j=0;j<(1<<l);j+=i<<1)for(int k=0;k<i;++k){
		f[i+j+k]=sub(f[i+j+k],f[j+k]);
	}
}
long long F[21][1<<N],G[21][1<<N],H[21][1<<N];
void solve()
{
	sort(a,a+n,cmp);
	{
		int ss=0;
		for(int i=0;i<n;i++) ss+=a[i].w;
		if(ss<=W)
		{
			printf("%d %d\n",a[n-1].c,1);
			return ;
		}
	}
	for(int i=1;i<1<<l;i++)
	{
		int u=__builtin_ctz(i);
		sum[i]=sum[i^(1<<u)]+a[u].w;
	}
	mn[0]=0,cnt[0]=1;
	int ful=(1<<l)-1;
	for(int i=1;i<1<<l;i++)
	{
		mn[i]=inf;
		int u=31-__builtin_clz(i);
		for(int st=i;st>=(1<<u);st=i&(st-1))
		{
			if(sum[st]<=W)
			{
				if(mn[i^st]+a[u].c<mn[i]) mn[i]=mn[i^st]+a[u].c,cnt[i]=0;
				if(mn[i^st]+a[u].c==mn[i]) inc(cnt[i],cnt[i^st]);
			}
		}
	}
	// for(int i=1;i<1<<n;i++) printf("%d %d %d\n",i,mn[i],cnt[i]);
	// printf("%d %d\n",mn[ful],cnt[ful]);
	int amn=inf; long long acnt=0;
	if(n==21)
	{
		for(int i=0;i<1<<l;i++)
		{
			if(sum[i]+a[n-1].w<=W)
			{
				if(a[n-1].c+mn[i^ful]<amn) amn=a[n-1].c+mn[i^ful],acnt=0;
				if(a[n-1].c+mn[i^ful]==amn) inc(acnt,cnt[i^ful]);
			}
		}
	}
	else
	{
		for(int i=0;i<1<<l;i++)
		{
			if(sum[i]+a[n-1].w+a[n-2].w<=W)
			{
				if(a[n-1].c+mn[i^ful]<amn) amn=a[n-1].c+mn[i^ful],acnt=0;
				if(a[n-1].c+mn[i^ful]==amn) inc(acnt,cnt[i^ful]);
			}
		}
		int w1=W-a[n-1].w,w2=W-a[n-2].w;
		int tmn=inf; long long tcnt=0;
		/*for(int i=0;i<1<<l;i++)
		{
			int ok1=sum[i]<=w1,ok2=sum[i]<=w2;
			if(!ok1&&!ok2) continue;
			int r=ful^i;
			
			for(int j=r;j>i;j=r&(j-1))
			{
				int to1=sum[j]<=w1,to2=sum[j]<=w2;
				int cntok=(to1&&ok2)+(to2&&ok1);
				if(cntok)
				{
					if(mn[r^j]<tmn) tmn=mn[r^j],tcnt=0;
					if(mn[r^j]==tmn) inc(tcnt,cnt[r^j]<<(cntok-1));
				}
			}
		}*/
		for(int i=0;i<(1<<l);++i){
			if(a[n-1].c+sum[i]<=W)F[__builtin_popcount(i)][i]=1;
			if(a[n-2].c+sum[i]<=W)G[__builtin_popcount(i)][i]=1;
		}
		for(int i=0;i<=l;++i){
			fwt(F[i]);
			fwt(G[i]);
		}
		for(int j=0;j<=l;++j){
			for(int k=0;k+j<=l;++k){
				for(int i=0;i<(1<<l);++i){
					H[j+k][i]=add(H[j+k][i],mul(F[j][i],G[k][i]));
				}
			}
		}
		for(int i=0;i<=l;++i){
			ifwt(H[i]);
		}
		for(int i=0;i<(1<<l);++i){
			int cur=H[__builtin_popcount(i)][i];
			if(cur){
				if(a[n-1].c+a[n-2].c+mn[ful^i]<amn){
					amn=a[n-1].c+a[n-2].c+mn[ful^i];
					acnt=0;
				}
				if(a[n-1].c+a[n-2].c+mn[ful^i]==amn){
					inc(acnt,mul(cur,cnt[ful^i]));
				}
			}
		}
		int ful=(1<<l)-1;
		if(a[n-1].c+a[n-2].c+mn[ful]<amn) amn=a[n-1].c+a[n-2].c+mn[ful],acnt=0;
		if(a[n-1].c+a[n-2].c+mn[ful]==amn) inc(acnt,cnt[ful]);
		if(tmn+a[n-1].c+a[n-2].c<amn) amn=tmn+a[n-1].c+a[n-2].c;
		if(tmn+a[n-1].c+a[n-2].c==amn) inc(acnt,tcnt);
	}
	printf("%d %lld\n",amn,acnt%mod);
}
signed main()
{
#ifdef xay5421
	freopen("a.in","r",stdin);
#endif
	cin>>n>>W;
	for(int i=0;i<n;i++) a[i].w=read(),a[i].c=read();
	if(n<=20) bf();
	else solve();
	
	return 0;
}


Details

answer.code: In function ‘void solve()’:
answer.code:153:32: error: cannot convert ‘long long int*’ to ‘int*’
  153 |                         fwt(F[i]);
      |                             ~~~^
      |                                |
      |                                long long int*
answer.code:62:15: note:   initializing argument 1 of ‘void fwt(int*)’
   62 | void fwt(int *f){
      |          ~~~~~^
answer.code:154:32: error: cannot convert ‘long long int*’ to ‘int*’
  154 |                         fwt(G[i]);
      |                             ~~~^
      |                                |
      |                                long long int*
answer.code:62:15: note:   initializing argument 1 of ‘void fwt(int*)’
   62 | void fwt(int *f){
      |          ~~~~~^
answer.code:164:33: error: cannot convert ‘long long int*’ to ‘int*’
  164 |                         ifwt(H[i]);
      |                              ~~~^
      |                                 |
      |                                 long long int*
answer.code:67:16: note:   initializing argument 1 of ‘void ifwt(int*)’
   67 | void ifwt(int *f){
      |           ~~~~~^