# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1205031 | irmuun | Rotating Lines (APIO25_rotate) | C++20 | 0 ms | 0 KiB |
#include "rotate.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
const int lim=50000;
int till(int x,int y){
if(x<=y) return y-x;
return lim-(x-y);
}
void energy(int n, vector<int> v){
if(n==2){
rotate({1},till(v[1],(v[0]+lim/2)%lim));
return 0;
}
vector<int>ord(n);
iota(all(ord),0);
sort(all(ord),[&](int i,int j){
return v[i]<v[j];
});
int r=n-1;
for(int i=1;i<=n/2;i++){
rotate({ord[r]},till(v[ord[r]],25000));
r--;
}
int l=0;
for(int i=1;i<=n/2;i++){
rotate({ord[l]},till(v[ord[l]],0));
l++;
}
if(n%2==1){
rotate({ord[n/2]},till(v[ord[n/2]],12500));
}
}