Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: nik121416

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

Language: cpp

Time: 0.003 second

Submitted On: 2025-10-15 21:15:20

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

bool cmp(string a,string b){

    return a+b> b+a;
}

int main(){
    int n;
    cin >> n;
    vector<string> bi;
    for(int i = 0 ;i<n;i++){
        int num;
        cin >> num;
        string s = "";
        while(num!=0){
            if(num%2 == 0){
                s.push_back('0');
            }
            else{
                s.push_back('1');
            }
            num/=2;
        }
        reverse(s.begin(),s.end());
        bi.push_back(s);
    }
    sort(bi.begin(), bi.end(),cmp);
    string binary = "";
    for(string i:bi){
        binary+=i;
    }
    cout << stoi(binary,nullptr,2);
}