Submission

Status:

PPPPPPP-PP

Subtask/Task Score:

90/100

Score: 90

User: Zailagend1

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

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-06 13:42:12

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    cin.tie(0)->sync_with_stdio(false);
    int a;
    cin >> a;
    
    vector<pair<string,int>> group;
    for(int i = 0;i<a;i++){
        string sum = "";
        int b;
        cin >> b;
        bitset<7> num(b);
        bool start = false;
        
        for(char x : num.to_string()){
            if(x == '0' && start){
                sum += x;
            }
            if(x == '1'){
                start = true;
                sum += x;
            }
        }
        group.push_back({sum,b});
    }
    sort(group.begin(),group.end(),[](pair<string,long long> a,pair<string,long long> b){
        int exp = 8;
        int counter1 = 0;
        int counter2 = 0;
        for(char x : a.first){
            if(x == '1'){
                counter1 += pow(2,exp);
            }
            exp--;
        }
        exp = 8;
        for(char x : b.first){
            if(x == '1'){
                counter2 += pow(2,exp);
            }
            exp--;
        }
        return counter1 > counter2;
    });
    string sum3 ="";
    for(auto[x,y] : group){
        sum3+=x;
    }
    int exp = sum3.size()-1;
    int sum2 = 0;
    for(char x : sum3){
        if(x == '1'){
            sum2 += (pow(2,exp));
        }
        exp--;
    }
    cout << sum2;
}