답안 #67827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67827 2018-08-15T10:41:48 Z ege_eksi XOR Sum (info1cup17_xorsum) C++14
18 / 100
184 ms 4460 KB
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<algorithm>

using namespace std;

int *v;

int main()
{
	int n;
	scanf("%d",&n);
	
	v = new int[n];
	
	int x = 0;
	
	for(int i = 0 ; i < n ; i++)
	{
		scanf("%d",&v[i]);
		x = max(x , v[i]);
	}
	
	if(n <= 4000){
		long long int ans = 0;
	
		int i , j;
	
		for(i = 0 ; i < n ; i++)
		{
			for(j = i ; j < n ; j++)
			{
				ans = ans ^ (v[i] + v[j]);
			}
		}
		
		printf("%lli",ans);
		
		return 0;
	}
	
	if(x <= 4000)
	{
		int cnt[4001] = {0};
		
		int i , j;
		
		for(i = 0 ; i < n ; i++)
		{
			cnt[v[i]]++;
		}
		/*
		for(i = 1 ; i <= x ; i++)
		{
			printf("%d: %d\n",i , cnt[i]);
		}
		*/
		long long int ans = 0;
		
		for(i = 1 ; i <= x ; i++)
		{
			if(cnt[i] != 0)
			{
				if((cnt[i] + cnt[i] * (cnt[i]-1) / 2) % 2 != 0)
				{
					ans = ans ^ (i+i);
				}
				
				for(j = i+1 ; j <= x ; j++)
				{
					if(cnt[j] != 0)
					{
						if((cnt[i] * cnt[j]) % 2 != 0)
						{
							ans = ans ^ (i+j);
						}
					}
				}
			}
		}
		
		printf("%lli" , ans);
		
		return 0;
	}
	
	return 0;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
xorsum.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&v[i]);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 248 KB Output is correct
2 Correct 12 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 4316 KB Output is correct
2 Correct 149 ms 4316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 4316 KB Output is correct
2 Correct 149 ms 4316 KB Output is correct
3 Incorrect 172 ms 4460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 248 KB Output is correct
2 Correct 12 ms 484 KB Output is correct
3 Incorrect 29 ms 4460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 248 KB Output is correct
2 Correct 12 ms 484 KB Output is correct
3 Correct 184 ms 4316 KB Output is correct
4 Correct 149 ms 4316 KB Output is correct
5 Incorrect 172 ms 4460 KB Output isn't correct
6 Halted 0 ms 0 KB -