Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: porpeang

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

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-08 13:42:17

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



string decToBaseB(long long n, int base) {
    if (n == 0) return "0";
    string res = "";
    while (n > 0) {
        res += to_string(n % base); // เก็บเศษ
        n /= base;
    }
    reverse(res.begin(), res.end()); // ย้อนกลับสตริง
    return res;
}
int main(){
    int a=0,b=0,c=0,d=0;
    cin>>a;
    vector<string>bin;
    vector<int>vev;
    for(int i=0;i<a;i++){
        cin>>b;
        bin.push_back(decToBaseB(b,2));
    }


    sort(bin.begin(), bin.end());

    unsigned long long max_val = 0;

    // 2. วนลูปสลับเรียงลำดับไปเรื่อยๆ จนครบทุกแบบ
    do {
        // ต่อสตริงในรอบนี้เข้าด้วยกัน
        string combined = "";
        for (string s : bin) {
            combined += s;
        }

        // แปลงฐาน 2 เป็นฐาน 10 และหาค่าสูงสุด
        unsigned long long val = stoull(combined, nullptr, 2);
        max_val = max(max_val, val);

    } while (next_permutation(bin.begin(), bin.end()));

    cout << max_val << '\n';

}