답안 #348955

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348955 2021-01-16T07:38:10 Z ali_tavakoli XOR Sum (info1cup17_xorsum) C++14
18 / 100
1600 ms 8172 KB
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define pb push_back
#define F first
#define S second
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")

const int maxn = 1e6 + 5, mxn = 4e3 + 5;

int n, a[maxn], cnt[maxn];

void sub1()
{
	ll ans = 0;
	for(int i = 0; i < n; i++)
		for(int j = i; j < n; j++)
			ans ^= (a[i] + a[j]);
	cout << ans << '\n';
}

void sub2()
{
	ll ans = 0;
	for(int i = 0; i < n; i++)
		cnt[a[i]] ++;
	for(int i = 0; i < mxn; i++)
		for(int j = i + 1; j < mxn; j++)
			if((cnt[i] * cnt[j]) % 2)
				ans ^= (i + j);
	//cout << ans << '\n';
	for(int i = 0; i < mxn; i++)
		if((cnt[i] * (cnt[i] - 1) / 2 + cnt[i]) % 2)
			ans ^= (i + i);
	cout << ans << '\n';
}

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	auto t = clock();
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	
	if(n <= (1e5))
		sub1();
	else
		sub2();
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:44:7: warning: unused variable 't' [-Wunused-variable]
   44 |  auto t = clock();
      |       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 364 KB Output is correct
2 Correct 4 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 4332 KB Output is correct
2 Correct 89 ms 3948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 4332 KB Output is correct
2 Correct 89 ms 3948 KB Output is correct
3 Incorrect 114 ms 8172 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 364 KB Output is correct
2 Correct 4 ms 364 KB Output is correct
3 Execution timed out 1683 ms 768 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 364 KB Output is correct
2 Correct 4 ms 364 KB Output is correct
3 Correct 97 ms 4332 KB Output is correct
4 Correct 89 ms 3948 KB Output is correct
5 Incorrect 114 ms 8172 KB Output isn't correct
6 Halted 0 ms 0 KB -