QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561372#8790. First Billioncppcppcpp3WA 0ms3628kbC++202.6kb2024-09-12 22:02:282024-09-12 22:02:29

Judging History

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

  • [2024-09-12 22:02:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3628kb
  • [2024-09-12 22:02:28]
  • 提交

answer

#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=105;
const int inf=1e9+7;

static char buf[1000000],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++
inline int wrd(){int x=0,f=1;char c=getchar();while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();}while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+c-48;c=getchar();}return x*f;}
inline void write(int x){static char buf[20];static int len=-1;if(x<0)putchar('-'),x=-x;do buf[++len]=x%10,x/=10;while(x);while(len>=0)putchar(buf[len--]+48);}

int n,K,B,a[N],id[N];
pii b[N];

namespace sub1{
	map<int,int> mp[2];
	void dfs(int dep,int st,int sum,int o,int lim){
		if(dep>lim){
			mp[o][sum]=st;
			return;
		}
		dfs(dep+1,st,sum,o,lim);
		dfs(dep+1,st|(1<<(dep-1)),sum+a[dep+(!o?0:n-lim)],o,lim);
	}
	
	void solve(){
		int u=n/2,v=n-u;
		dfs(1,0,0,0,u),dfs(1,0,0,1,v);
		for(auto h:mp[0]){
			if(!mp[1].count((int)1e9-h.fi)) continue;
			int x=h.se,y=mp[1][(int)1e9-h.fi];
			write(__builtin_popcount(x)+__builtin_popcount(y)),putchar(' ');
			for(int i=1;i<=u;++i) if((x>>(i-1))&1) write(id[i]),putchar(' ');
			for(int i=1;i<=v;++i) if((y>>(i-1))&1) write(id[u+i]),putchar(' ');
			exit(0); 
		}
	}
}

namespace sub2{
	vector<int> res[6],d[6];
	int c[6],L[6],R[6];
	pii f[1<<24];
	
	void calc(int l,int r,int id){
		L[id]=l,R[id]=r;
		int sz=r-l+1,all=(1<<sz)-1,tot=0;
		for(int i=l;i<=r;++i) tot+=a[i];
		for(int s=0;s<=all;++s){
			int tt=0;
			for(int i=L[id];i<=R[id];++i)
				if((s>>(i-L[id]))&1) tt+=a[i];
			f[s]={abs(2*tt-tot),s};
		}
		sort(f,f+all+1);
		for(int i=all+1;i<=K;++i) f[i]={inf,-1};
		for(int s=0;s<=K;++s) res[id].push_back(f[s].fi),d[id].push_back(f[s].se);
	}
	
	void dfs(int dep,int sum){
		if(sum==1e9){
			int as=0;
			for(int i=1;i<=B;++i) as+=__builtin_popcount(d[i][c[i]]);
			write(as),putchar(' ');
			for(int i=1;i<=B;++i)
				for(int j=L[i];j<=R[i];++j) 
					if((d[i][c[i]]>>(j-L[i]))&1) write(id[j]),putchar(' ');
			 exit(0);
		}
		if(sum>1e9 || dep>B) return;
		for(int i=0;i<K;++i)
			c[dep]=i,dfs(dep+1,sum+res[dep][i]);
	}
	
	void solve(){
		int len=(n+B-1)/B;
		for(int i=1;i<=B;++i) calc((i-1)*len+1,min(n,i*len),i);
		dfs(1,0);
	}
}

signed main(){
	n=wrd();
	for(int i=1;i<=n;++i) a[i]=wrd(),b[i]={a[i],i};
	sort(a+1,a+n+1),sort(b+1,b+n+1);
	for(int i=1;i<=n;++i) id[i]=b[i].se;
	if(n<=18) B=1,K=(1<<n)-1;
	else if(n<=40) return sub1::solve(),0;
	else if(n<=60) B=3,K=1024;
	else if(n<=80) B=4,K=150;
	else if(n<=100) B=5,K=25;
	return sub2::solve(),0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3628kb

input:

10
386413329 88494216 245947398 316438989 192751270 204627269 65749456 3938400 150458676 345180997

output:


result:

wrong output format Unexpected end of file - int32 expected