Submission
Status:
PPPPPPP-PP
Score: 90
User: meme_boi2
Problemset: วิศวกรรมข้อมูล
Language: cpp
Time: 0.002 second
Submitted On: 2024-12-09 09:20:08
/*
TASK: data eng
LANG: C++
AUTHOR: CCSleep Broke me
CENTER: SUT
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
string tobin(int n){
string txt = "";
if(n == 0) return "0";
while(n != 0){
txt = to_string(n%2) + txt;
n /= 2;
}
return txt;
}
bool comp(int a, int b){
string t1 = tobin(a), t2 = tobin(b);
return t1 + t2 > t2 + t1;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(0);
int n; string txt;
vector <int> mat;
cin >> n;
while(n--){
int c;
cin>> c;
mat.push_back(c);
}
sort(mat.begin(),mat.end(), comp);
if(mat.size() >= 3)txt = tobin(mat[0]) + tobin(mat[1]) + tobin(mat[2]);
if(mat.size() == 2)txt = tobin(mat[0]) + tobin(mat[1]);
else txt = tobin(mat[0]);
//cout << txt[0] << '\n';
int num = 0;
for(int i = 0; i < txt.length(); i++){
num += (txt[txt.length()-i-1]-'0')*pow(2, i);
}
cout << num;
}