compro-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub ningenMe/compro-library

:heavy_check_mark: test/util/NBase.test.cpp

Depends on

Code

#define PROBLEM "https://yukicoder.me/problems/no/699"

#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;
#include "../../lib/00-util/NBase.cpp"

int main(void){
	int N; cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(),A.end());
    vector<long long> B(N/2),C(N/2);
    long long ans = 0;
    for(int i = 0; i < (1<<N); ++i) {
        if(i&1 || NBase::digit_sum(i,2)!=N/2) continue;
        int b=0,c=0;
        for(int j = 0; j < N; ++j) {
            if(i&(1<<j)) B[b++]=A[j];
            else C[c++]=A[j];
        }
        do{
            long long sum = 0;
            for(int j = 0; j < N/2; ++j) {
                sum ^= (B[j]+C[j]);
            }
			ans = max(ans,sum);
        }while (next_permutation(B.begin(),B.end()));
    }
    cout << ans << endl;

	return 0;
}
#line 1 "test/util/NBase.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/699"

#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
using namespace std;
#line 1 "lib/00-util/NBase.cpp"
/*
 * @title NBase - N進数
 * @docs md/util/NBase.md
 */
class NBase{
public:
	inline static vector<long long> translate(long long X,long long N) {
		assert(abs(N)>1);
		vector<long long> res;
		while(1) {
			long long b = (X%abs(N)+abs(N)) % abs(N);
			res.push_back(b);
			(X -= b) /= N;
			if(X==0) break;
		}
		return res;
	}
	//Digit Sum
	inline static constexpr long long digit_sum(long long N, long long K) {
		long long sum = 0;
		for (; N > 0; N /= K) sum += N % K;
		return sum;
	}
};
#line 9 "test/util/NBase.test.cpp"

int main(void){
	int N; cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(),A.end());
    vector<long long> B(N/2),C(N/2);
    long long ans = 0;
    for(int i = 0; i < (1<<N); ++i) {
        if(i&1 || NBase::digit_sum(i,2)!=N/2) continue;
        int b=0,c=0;
        for(int j = 0; j < N; ++j) {
            if(i&(1<<j)) B[b++]=A[j];
            else C[c++]=A[j];
        }
        do{
            long long sum = 0;
            for(int j = 0; j < N/2; ++j) {
                sum ^= (B[j]+C[j]);
            }
			ans = max(ans,sum);
        }while (next_permutation(B.begin(),B.end()));
    }
    cout << ans << endl;

	return 0;
}
Back to top page