Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: speedbuffalo99
Problemset: วิศวกรรมข้อมูล
Language: cpp
Time: 0.005 second
Submitted On: 2026-10-15 16:43:49
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
// ?ŧ?ӹǹ?????ʵ?ԧ?Ţ?ҹ?ͧ
string toBinary(int x) {
string s = "";
while (x > 0) {
s += char('0' + x % 2);
x /= 2;
}
reverse(s.begin(), s.end());
return s;
}
int main() {
int n;
cin >> n;
int a[4];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
string b[4];
for (int i = 0; i < n; i++) {
b[i] = toBinary(a[i]);
}
sort(b, b + n);
string best = "";
do {
string current = "";
for (int i = 0; i < n; i++) {
current += b[i];
}
if (current > best) {
best = current;
}
} while (next_permutation(b, b + n));
unsigned long long ans = 0;
for (int i = 0; i < (int)best.size(); i++) {
ans = ans * 2 + (best[i] - '0');
}
cout << ans << '\n';
return 0;
}