/ Randle /

记录详情

Runtime Error

/in/foo.cc: In function 'int main()':
/in/foo.cc:93:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(((unsigned int)1<<k)<=a[i]&&(a[i]&((unsigned int)1<<k)))
       ~~~~~~~~~~~~~~~~~~~~^~~~~~
/in/foo.cc:83:10: warning: unused variable 's' [-Wunused-variable]
  int i,k,s;
          ^
# 状态 耗时 内存占用
#1 Accepted 3ms 436.0 KiB
#2 Accepted 2ms 440.0 KiB
#3 Accepted 2ms 452.0 KiB
#4 Runtime Error 3ms 4.68 MiB
#5 Runtime Error 3ms 4.676 MiB
#6 Runtime Error 3ms 4.676 MiB
#7 Runtime Error 3ms 4.676 MiB
#8 Runtime Error 3ms 4.805 MiB
#9 Runtime Error 3ms 4.816 MiB
#10 Runtime Error 3ms 4.848 MiB

代码

#include<bits/stdc++.h>
using namespace std;
int n,a[1001],v[32][1001],h[1001],ans2[32],b[1001][31];//h±íʾÒѾ­È¡³öµÄÊýµÄ±ê¼Ç 
long long ans=0;
struct node
{
	int a,data;
};
inline const void read(int &a)
{
	a=0;
	char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	}
}
bool com1(node aa,node bb)
{
	return aa.data<bb.data;
}
void find(node *x,int len)
{
	//if(p==1)
	//for(int i=1;i<=len;i++)
	//cout<<"temp["<<i<<"].a="<<x[i].a<<"  temp["<<i<<"].data="<<x[i].data<<endl;
	node temp[1001];
	int jk=0;
	sort(x+1,x+1+len,com1);
	temp[++jk].a=x[1].a;
	for(int i=1;i<=b[x[1].a][0];i++)
	{
		//cout<<b[x[1].a][i]<<' '<<x[1].data<<endl;
		if(b[x[1].a][i]<x[1].data)
		{
			//cout<<"**\n";
		    temp[jk].data=b[x[1].a][i];
		    break;
		}
	}
	for(int i=2;i<=len;i++)
	{
		if(x[i].data==x[i-1].data)
		{
			temp[++jk].a=x[i].a;
			for(int o=1;o<=b[x[i].a][0];o++)
			{
				if(b[x[i].a][o]<x[i].data)
				{
					temp[jk].data=b[x[i].a][o];
					break;
				}
			}
		}
		else break;
	}
	if(jk==1)
	{
		//cout<<"*********\n";
		//cout<<"temp["<<jk<<"].a="<<temp[jk].a<<" temp["<<jk<<"].data="<<temp[jk].data<<endl;
		//cout<<"**********\n";
		h[temp[jk].a]=1;
		return;
	}
	else 
	{
		//cout<<"**&&&&**\n";
		//for(int jj=1;jj<=jk;jj++)
		//cout<<"temp["<<jj<<"].a="<<temp[jj].a<<" temp["<<jj<<"].data="<<temp[jj].data<<endl;
		//cout<<"**&&&&**\n";
	    find(temp,jk);
	}
}
bool com(int a,int b)
{
	return a>b;
}
int main()
{
	//freopen("ji.in.txt","r",stdin);
	int i,k,s;
	memset(v,0,sizeof(v));
	memset(h,0,sizeof(h));
	memset(ans2,0,sizeof(ans2));
	read(n);
	for(i=1;i<=n;i++) read(a[i]);
	for(i=1;i<=n;i++)
	{
		for(k=31;k>=0;k--)
		{
			if(((unsigned int)1<<k)<=a[i]&&(a[i]&((unsigned int)1<<k)))
			{
				b[i][++b[i][0]]=k;
				v[k][++v[k][0]]=i;
			}
		}
	}
	//for(int o=1;o<=n;o++)
	//for(int x=1;x<=b[o][0];x++)
	//cout<<"b["<<o<<"]["<<x<<"]="<<b[o][x]<<endl;
	//for(int i=0;i<=31;i++)
	//cout<<v[i][0]<<' ';
	//cout<<endl;
	for(i=31;i>=0;i--)
	{//cout<<"**"<<i<<endl;
		if(v[i][0])
		{
		    //cout<<"v["<<i<<"][0]="<<v[i][0]<<endl;   
			if(v[i][0]==1&&!h[v[i][1]])
			{
				ans2[i]=1;
				h[v[i][1]]=1;
			}
			else 
			{//cout<<"**"<<i<<endl;
				node temp[1001];
				int jk=0;
				//for(int j=1;j<=v[i][0];j++)
				//cout<<"v["<<i<<"]["<<j<<"]="<<v[i][j]<<' ';
				//cout<<endl;
				for(int j=1;j<=v[i][0];j++)
				{
					if(!h[v[i][j]])
					{
					  //  cout<<")()(\n";
					    temp[++jk].a=v[i][j];
					    int mm=0;
					    for(int o=1;o<=b[v[i][j]][0];o++)
			    		{
				    		//cout<<"j="<<v[i][j]<<"  vvv="<<b[v[i][j]][o]<<endl;
				    		if(!ans2[b[v[i][j]][o]])
				    		{
					    		mm++;
						    	if(mm==2)
						    	{
						    	    temp[jk].data=b[v[i][j]][o];
					    		    break;
				    			}
				    		}
				    	}
					}
				}
				//cout<<endl<<"i="<<i<<" v["<<i<<"][0]="<<v[i][0]<<" jk="<<jk<<endl;
				//for(int lk=1;lk<=jk;lk++)
				//cout<<"temp["<<lk<<"].a="<<temp[lk].a<<"  temp["<<lk<<"].data="<<temp[lk].data<<endl;
				//for(int ww=1;ww<=n;ww++)
				//cout<<"h["<<ww<<"]="<<h[ww]<<' ';
				//cout<<endl;
				if(jk)
				{
					ans2[i]=1;
				    find(temp,jk);
				}
			}	
		}
	}
	for(i=1;i<=n;i++)
	{
		if(!h[i])
		ans2[0]=abs(ans2[0]-1);
	}
	for(i=0;i<=31;i++)
		if(ans2[i])
		    ans+=((unsigned int)1<<i);
	cout<<ans<<endl;
	return 0;
}

信息

递交者
类型
递交
题目
奇数异或(国家集训队)
题目数据
下载
语言
C++
递交时间
2017-10-11 19:51:31
评测时间
2017-10-11 19:51:31
评测机
分数
30
总耗时
34ms
峰值内存
4.848 MiB