Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: navysrimuang
Problemset: วิศวกรรมข้อมูล
Language: cpp
Time: 0.003 second
Submitted On: 2025-10-03 20:32:15
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
string tobin(int x){
if(x == 0){
return "0";
}
string prod;
while(x!=0){
int r = x%2;
prod += ('0' + r);
x/=2;
}
reverse(prod.begin(), prod.end());
return prod;
}
bool cmp(string a,string b){
return (a+b) > (b+a);
}
int main(){
int n; cin >> n;
vector<string> v (n);
for(int i = 0;i<n;i++){
int x; cin >> x;
v[i] = tobin(x);
}
sort(v.begin(), v.end(), cmp);
string binres;
for(auto s:v){
binres += s;
}
int dec = stoi(binres, nullptr, 2);
cout << dec << endl;
return 0;
}