답안 #97865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97865 2019-02-19T06:46:15 Z mohammedehab2002 XOR Sum (info1cup17_xorsum) C++11
7 / 100
728 ms 16180 KB
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> v;
int f(unsigned int x)
{
	int r=v.size(),ans=0;
	for (int l=0;l<v.size();l++)
	{
		r=max(r,l);
		while (r>l && v[l]+v[r-1]>=x)
		r--;
		ans+=r-l;
	}
	return ans;
}
int main()
{
	int n,ans=0;
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		int a;
		scanf("%d",&a);
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	for (unsigned int i=(1<<29);i;i/=2)
	{
		vector<int> v1,v2;
		for (int j:v)
		{
			if (j<2*i)
			v1.push_back(j);
			else
			v2.push_back(j-2*i);
		}
		v.clear();
		merge(v1.begin(),v1.end(),v2.begin(),v2.end(),back_inserter(v));
		int cnt=f(4*i)-f(3*i)+f(2*i)-f(i);
		ans+=i*(cnt%2);
	}
	printf("%d",ans);
}

Compilation message

xorsum.cpp: In function 'int f(unsigned int)':
xorsum.cpp:9:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int l=0;l<v.size();l++)
               ~^~~~~~~~~
xorsum.cpp:12:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (r>l && v[l]+v[r-1]>=x)
xorsum.cpp: In function 'int main()':
xorsum.cpp:34:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (j<2*i)
        ~^~~~
xorsum.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
xorsum.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a);
   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 728 ms 16180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 728 ms 16180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Incorrect 80 ms 2508 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Incorrect 728 ms 16180 KB Output isn't correct
4 Halted 0 ms 0 KB -