Submission
Status:
PP-PPPP-PP
Subtask/Task Score:
80/100
Score: 80
User: august
Problemset: วิศวกรรมข้อมูล
Language: cpp
Time: 0.002 second
Submitted On: 2025-10-13 09:51:21
#include <bits/stdc++.h>
using namespace std;
struct N {
int cnt1=0, si, cons1;
string bit;
};
int main() {
int n;
cin>> n;
int a[n];
for (int i=0; i<n; i++) cin>> a[i];
struct N b[n];
for (int i=0; i<n; i++) {
string s="";
while (a[i] != 0) {
b[i].cnt1 += a[i]%2;
s=char('0'+a[i]%2)+s;
a[i]/=2;
}
b[i].bit = s;
b[i].si=s.size();
int c=0;
for (int j=0; j<s.size(); j++) {
if (s[j] == '1') c++;
else break;
}
b[i].cons1=c;
}
for (int i=0; i<n-1; i++) {
for (int j=0; j<n-i-1; j++) {
if (b[j].cnt1 < b[j+1].cnt1) {
struct N t = b[j];
b[j]=b[j+1];
b[j+1]=t;
}
else if (b[j].cnt1 == b[j+1].cnt1) {
if (b[j].si > b[j+1].si) {
struct N t = b[j];
b[j]=b[j+1];
b[j+1]=t;
}
else if (b[j].si == b[j+1].si) {
if (b[j].cons1 < b[j+1].cons1) {
struct N t = b[j];
b[j]=b[j+1];
b[j+1]=t;
}
}
}
}
}
string st="";
for (int i=0; i<n; i++) {
st+=b[i].bit;
}
unsigned long long ans=0;
for (int i=0; i<st.size(); i++) {
ans*=2;
ans+=st[i]-'0';
}
cout<< ans;
}