Submission #1317245

#TimeUsernameProblemLanguageResultExecution timeMemory
1317245jesusargRotating Lines (APIO25_rotate)C++20
13 / 100
3093 ms3836 KiB
#include <bits/stdc++.h>
#define ll long long 
#define pb push_back
#define f first
#define s second
#define sz size()
using namespace std;

void rotate(std::vector<int> t, int x);

void energy(int n, vector<int> v){
    int tot=50000;
    int nov=25000;
    bool ok=1;
    while(ok){
        ok=0;
        ll best=-1e9;
        vector<int> ans;
        int bbx = 0;
        for(int j = 1; j < (1<<n); j++){
            vector<int> v2, v3;
            for(int i = 0; i < n; i++){
                if(j&(1<<i)){
                    v2.pb(i);
                } else {
                    v3.pb(i);
                }
            }
            if(v2.empty() || v3.empty()) continue;
            set<int> cand;
            for(auto el : v2){
                for(auto l : v3){
                    ll x1 = ((-(v[el]-v[l]+tot)%tot)+tot)%tot;
                    ll x2 = ((nov-(v[el]-v[l]+tot)%tot)+tot)%tot;
                    cand.insert(x1);
                    cand.insert(x2);
                }
            }
            ll bcurr=-1e9;
            int bx=0;
            for(auto xx : cand){
                ll curr = 0;
                for(auto el : v2){
                    int vv = (v[el]+xx)%tot;
                    for(auto l : v3){
                        int prev = min(abs(v[el]-v[l]),tot-abs(v[el]-v[l]));
                        int cur = min(abs(vv-v[l]),tot-abs(vv-v[l]));
                        curr += (ll)(cur-prev);
                    }
                }
                if(curr > bcurr){
                    bcurr=curr;
                    bx=xx;
                }
            }
            if(bcurr > best){
                best=bcurr;
                ans=v2;
                bbx=bx;
            }
        }
        if(best > 0){
            ok=1;
            rotate(ans, bbx);
            for(auto idx : ans){
                v[idx]=(v[idx]+bbx)%tot;
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...