Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: nemuchannnUwU

Problemset: วิศวกรรมข้อมูล

Language: cpp

Time: 0.003 second

Submitted On: 2025-10-15 17:19:30

#include<bits/stdc++.h>
using namespace std;
void permu(const vector<string> &v, string &sol, vector<string> &ans, vector<bool> &used, int chosen) {
    int n = v.size();
    if (chosen == n) {
        ans.push_back(sol);
        return;
    }
    for (int i = 0; i < n; ++i) {
        if (used[i]) continue;
        used[i] = true;
        string old = sol;
        sol += v[i];
        permu(v, sol, ans, used, chosen + 1);
        sol = old;
        used[i] = false; 
    }
}
int main(){
	cin.tie(nullptr)->sync_with_stdio(0);
	int n;
	cin >> n;
	vector<string> v;
	for (int i=0;i<n;i++){
		int a; cin >> a;
		string s="";
		while(a>0){
			s+=to_string(a%2);
			a/=2;
		}
		reverse(s.begin(),s.end());
		v.push_back(s);
	}
	vector<string> all;
	string sol="";
	vector<bool> used(n,false);
	permu(v,sol,all,used,0);
	string mx="";
	for (auto x : all){
		mx=max(mx,x);
	}
//	cout << mx;
	int sum=0;
	for (char c : mx){
		sum=sum*2+(c-'0');
	}
	cout << sum;
//	for (auto x : all) cout << x << " ";
}