Submission
Status:
TTTTTTTTTT
Subtask/Task Score:
0/100
Score: 0
User: aomILOVEMYFRIEND
Problemset: วิศวกรรมข้อมูล
Language: cpp
Time: 1.097 second
Submitted On: 2025-10-09 23:46:53
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
int n,temp,temp1,temp2;
class cmp{
public:
bool operator()(string a,string b){
temp2=max(a.size(),b.size());
for(int i=0;i<temp2;i++){
if(i==a.size()){
return false;
}
if(i==b.size()){
return true;
}
if(a[i]>b[i]){
return false;
}
if(b[i]>a[i]){
return true;
}
}
return false;
}
};
string s;
priority_queue<string,vector<string>,cmp> pq;
int main(){
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for(int i=0;i<n;i++){
cin>>temp;
s="";
temp1=1;
while(temp1<=temp){
temp1=2;
}
temp1/=2;
while(temp1>0){
if(temp1<=temp){
temp-=temp1;
s+="1";
}
else{
s+="0";
}
temp1/=2;
}
pq.push(s);
}
s="";
while(!pq.empty()){
s+=pq.top();
pq.pop();
}
temp1=1;
temp2=0;
while(temp2<s.size()){
temp1=2;
temp2+=1;
}
temp1/=2;
n=0;
temp2=0;
while(temp1>0){
if(s[temp2]=='1'){
n+=temp1;
}
temp1/=2;
temp2+=1;
}
cout<<n;
}