Submission

Status:
PPPPPPPPPP

Score: 100

User: Dormon

Problemset: วิศวกรรมข้อมูล

Language: cpp

Time: 0.002 second

Submitted On: 2024-12-11 07:31:58

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <numeric>

#define debug(...) Debug(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
const bool TEST_CASE = 0;

template<typename T>
typename std::enable_if<std::is_integral<T>::value>::type
Debug(const char* name, T value) {
    std::cout << name << " : " << value << '\n';
}

template<typename T, typename... Args>
typename std::enable_if<std::is_integral<T>::value>::type
Debug(const char* names, T value, Args... args) {
    const char* comma = strchr(names, ',');
    std::cout.write(names, comma - names) << " : " << value << " | ";
    Debug(comma + 1, args...);
}
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {for(auto &x : a) out << x << ' '; return out;};

string to_base2(int n){
    string res = "";
    while (n){
        res += (n&1) + '0';
        n >>= 1;
    }
    reverse(res.begin(), res.end());
    return res;
}

int calc(string s){
    int ans = 0, base = 1;
    for (int i = s.size()-1;i >= 0;i--){
        ans += (s[i] - '0') * base;
        base <<= 1;
    }
    return ans;
}

void solve(){
    int n;
    cin >> n;
    vector<int> v(n);
    vector<string> val(n);

    for (int i = 0;i < n;i++){
        cin >> v[i];
        val[i] = to_base2(v[i]);
    }
    sort(val.begin(), val.end());
    int ans = 0;
    do {
        string res = "";
        for (auto s:val)
            res.append(s);
        ans = max(ans, calc(res));
    }while (next_permutation(val.begin(), val.end()));
    cout << ans << '\n';
}

#define DORMON

int main()
{
    #ifndef DORMON
        ios_base::sync_with_stdio(0); 
    #endif
    cin.tie(0);
    int q = 1; 
    if (TEST_CASE) cin >> q;
    while (q--){
        solve();
    }
}