记录详情

Time Exceeded

/in/foo.cc: In function 'int main()':
/in/foo.cc:31:10: warning: iteration 39 invokes undefined behavior [-Waggressive-loop-optimizations]
    if(f[i]!=ans&&ans1==0) ans1=f[i];
       ~~~^
/in/foo.cc:30:16: note: within this loop
   for(int i=1;i<=40;i++)
               ~^~~~
/in/foo.cc:32:21: warning: 'ans2' may be used uninitialized in this function [-Wmaybe-uninitialized]
    else if(f[i]!=ans&&ans2==0&&ans1!=f[i]) ans2=f[i];
            ~~~~~~~~~^~~~~~~~~
/in/foo.cc:32:30: warning: 'ans1' may be used uninitialized in this function [-Wmaybe-uninitialized]
    else if(f[i]!=ans&&ans2==0&&ans1!=f[i]) ans2=f[i];
            ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# 状态 耗时 内存占用
#1 Wrong Answer 3ms 256.0 KiB
#2 Accepted 2ms 256.0 KiB
#3 Accepted 10ms 384.0 KiB
#4 Accepted 21ms 372.0 KiB
#5 Wrong Answer 728ms 436.0 KiB
#6 Time Exceeded ≥1004ms ≥256.0 KiB
#7 Time Exceeded ≥1003ms ≥384.0 KiB
#8 Wrong Answer 703ms 312.0 KiB
#9 Wrong Answer 713ms 360.0 KiB
#10 Wrong Answer 687ms 336.0 KiB

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=40;
int f[N],ans;
int n,m,x;

int main(){
	scanf("%d%d",&n,&m);
	if(m==1){
		for(int i=1;i<=n;i++){
			scanf("%d",&x);
			ans^=x;	
		}
		printf("%d\n",ans);
	}
	else{
		for(int i=1;i<=n;i++){
			scanf("%d",&x);
			ans^=x; int l=1,p=x;
			while(x){
				if(x&1) f[l]^=p;
				x>>=1; l++;
			}
		}
		int ans1,ans2;
		for(int i=1;i<=40;i++)
			if(f[i]!=ans&&ans1==0) ans1=f[i];
			else if(f[i]!=ans&&ans2==0&&ans1!=f[i]) ans2=f[i];
		if(ans1>ans2) swap(ans1,ans2);
		printf("%d %d\n",ans1,ans2);
	}
	return 0;
}

信息

递交者
类型
递交
题目
亚由题
语言
C++
递交时间
2017-05-03 16:19:35
评测时间
2017-05-03 16:19:35
评测机
分数
30
总耗时
≥4879ms
峰值内存
≥436.0 KiB