답안 #128631

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128631 2019-07-11T07:49:13 Z E869120 XOR Sum (info1cup17_xorsum) C++14
0 / 100
1600 ms 20524 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int N, A[1 << 20];

int solve(int bit) {
	vector<int> vec; long long sum = 0;
	for (int i = 1; i <= N; i++) {
		vec.push_back(A[i] % (2 << bit));
		vec.push_back((A[i] % (2 << bit)) + (2 << bit));
	}
	sort(vec.begin(), vec.end());

	for (int i = 1; i <= N; i++) {
		int F = (3 << bit) - A[i]; F %= (2 << bit);
		int pos1 = lower_bound(vec.begin(), vec.end(), F) - vec.begin();
		int pos2 = lower_bound(vec.begin(), vec.end(), F + (1 << bit)) - vec.begin();
		sum += 1LL * (pos2 - pos1);
	}
	
	long long sum2 = 0;
	for (int i = 1; i <= N; i++) {
		if ((A[i] + A[i]) % (2 << bit) >= (1 << bit)) sum2++;
	}

	return (sum2 + (sum - sum2) / 2LL) % 2LL;
}

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
	int ans = 0;
	for (int i = 0; i <= 29; i++) {
		int t = solve(i);
		if (t == 1) ans += (1 << i);
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

xorsum.cpp:5:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
xorsum.cpp: In function 'int main()':
xorsum.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
xorsum.cpp:34:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
                               ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1645 ms 20524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1645 ms 20524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -