Submission #1347590

#TimeUsernameProblemLanguageResultExecution timeMemory
1347590raphaelpRotating Lines (APIO25_rotate)C++20
100 / 100
36 ms2416 KiB
#include "rotate.h"
#include <bits/stdc++.h>
using namespace std;

void energy(int n, std::vector<int> v)
{
    vector<pair<int, int>> Tab(n);
    for (int i = 0; i < n; i++)
        Tab[i] = {v[i], i};
    sort(Tab.begin(), Tab.end());
    int cut = 0, A = 0, B = 0;
    while (cut < n && Tab[cut].first < 25000)
        cut++;
    B = cut;
    while (A < n / 2 && B - cut < ceil((double)n / 2))
    {
        if (B - A > n - B + A)
        {
            vector<int> t = {Tab[A].second};
            rotate(t, -Tab[A].first);
            Tab[A].first = 0;
            A++;
        }
        else if (B - A < n - B + A)
        {
            vector<int> t = {Tab[B].second};
            rotate(t, 25000 - Tab[B].first);
            Tab[B].first = 25000;
            B++;
        }
        else
        {
            vector<int> t = {Tab[A].second, Tab[B].second};
            int temp = max(-Tab[A].first, 25000 - Tab[B].first);
            rotate(t, temp);
            Tab[A].first += temp;
            Tab[B].first += temp;
            if (Tab[A].first == 0)
                A++;
            if (Tab[B].first == 25000)
                B++;
        }
    }
    int a = 0, b = 0;
    for (int i = 0; i < n; i++)
    {
        if (Tab[i].first == 0 || Tab[i].first == 25000)
            continue;
        vector<int> t = {Tab[i].second};
        if (A == n / 2)
        {
            rotate(t, 25000 - Tab[i].first);
            Tab[i].first = 25000;
        }
        else
        {
            rotate(t, 50000 - Tab[i].first);
            Tab[i].first = 0;
        }
    }
    for (int i = 0; i < n; i++)
    {
        vector<int> t = {Tab[i].second};
        if (Tab[i].first)
        {
            b++;
            if (b > n / 2)
            {
                rotate(t, 25000);
                b--, a++;
            }
        }
        else
        {
            a++;
            if (a > n / 2)
            {
                rotate(t, 25000);
                a--, b++;
            }
        }
    }
}
#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...