제출 #1347559

#제출 시각아이디문제언어결과실행 시간메모리
1347559raphaelpRotating Lines (APIO25_rotate)C++20
0 / 100
0 ms1000 KiB
#include "rotate.h"
#include <bits/stdc++.h>
using namespace std;

void energy(int n, std::vector<int> v)
{
    vector<pair<int, int>> Tab;
    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 (cut - A > n - B)
        {
            vector<int> t = {Tab[A].second};
            rotate(t, -Tab[A].first);
            A++;
        }
        else if (cut - A < n - B)
        {
            vector<int> t = {Tab[B].second};
            rotate(t, 25000 - Tab[B].first);
            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++;
        }
    }
    for (int i = cut - 1; i >= A; i--)
    {
        vector<int> t = {Tab[i].second};
        rotate(t, 25000 - Tab[i].first);
    }
    for (int i = n - 1; i >= B; i--)
    {
        vector<int> t = {Tab[i].second};
        rotate(t, 50000 - Tab[i].first);
    }
}
#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...