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]; ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
代码
#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