Submission

Status:
PPPPPPPPPP

Score: 100

User: Winzzwz

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

Language: cpp

Time: 0.004 second

Submitted On: 2025-03-09 01:22:43

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int n,nn,mx;
vector<string> t;

string i2b(int i) {
    string ans = "";
    while (i) {
        if (i%2) {
            i--;
            ans += '1';
            i /= 2;
        } else {
            ans += '0';
            i /= 2;
        }
    }
    reverse(ans.begin(),ans.end());
    return ans;
}

int b2i (string s) {
    int sz = s.size();
    int sum = 0;
    for (int i = 0; i < sz; i++) {
        if (s[i] == '1') {
            int temp = 1;
            for (int j = 1; j <= sz-i-1; j++) {
                temp *= 2;
            }
            sum += temp;
        }
    }
    return sum;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> nn;
        t.push_back(i2b(nn));
    }
    do {
        string res = "";
        for (auto x : t) {
            res += x;
        }
        mx = max(mx,b2i(res));
    }while (next_permutation(t.begin(),t.end()));
    cout << mx;
    return 0;
}