Submission #1355184

#TimeUsernameProblemLanguageResultExecution timeMemory
1355184Trisanu_DasRotating Lines (APIO25_rotate)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;


void energy(int n, vector<int> v) {
    if (n <= 1) return;

    sort(v.begin(), v.end());
    vector<int> w = v;
    w.insert(w.end(), v.begin(), v.end());

    int best_shift = 0, best_diff = n;
    int cnt = 0, j = 0;
    for (int i = 0; i < n; ++i) {
        while (j < i + n && w[j] - w[i] < 25000) ++j;
        int cur = j - i;              
        int diff = abs(cur - n/2);
        int shift = (50000 - w[i]) % 50000;
        if (diff < best_diff) {
            best_diff = diff;
            best_shift = shift;
        }
    }

    if (best_shift != 0) {
        vector<int> all(n);
        iota(all.begin(), all.end(), 0);
        rotate(all, best_shift);
        for (int &x : v) x = (x + best_shift) % 50000;
    }

    vector<int> target(n);
    vector<pair<int, int>> order; 
    for (int i = 0; i < n; ++i) {
        target[i] = (v[i] < 25000) ? 0 : 25000;
        int dist = min(abs(v[i] - target[i]), 50000 - abs(v[i] - target[i]));
        order.emplace_back(dist, i);
    }
    sort(order.rbegin(), order.rend());
    for (auto [dist, i] : order) {
        int move = (target[i] - v[i] + 50000) % 50000;
        if (move != 0) {
            rotate({i}, move);
            v[i] = target[i];
        }
    }
}

Compilation message (stderr)

rotate.cpp: In function 'void energy(int, std::vector<int>)':
rotate.cpp:28:15: error: no matching function for call to 'rotate(std::vector<int>&, int&)'
   28 |         rotate(all, best_shift);
      |         ~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from rotate.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:1390:5: note: candidate: 'template<class _FIter> constexpr _FIter std::_V2::rotate(_FIter, _FIter, _FIter)'
 1390 |     rotate(_ForwardIterator __first, _ForwardIterator __middle,
      |     ^~~~~~
/usr/include/c++/13/bits/stl_algo.h:1390:5: note:   template argument deduction/substitution failed:
rotate.cpp:28:15: note:   deduced conflicting types for parameter '_FIter' ('std::vector<int>' and 'int')
   28 |         rotate(all, best_shift);
      |         ~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:73:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:260:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::rotate(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _ForwardIterator)'
  260 | rotate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last);
      | ^~~~~~
/usr/include/c++/13/pstl/glue_algorithm_defs.h:260:1: note:   template argument deduction/substitution failed:
rotate.cpp:28:15: note:   candidate expects 4 arguments, 2 provided
   28 |         rotate(all, best_shift);
      |         ~~~~~~^~~~~~~~~~~~~~~~~
rotate.cpp:43:19: error: no matching function for call to 'rotate(<brace-enclosed initializer list>, int&)'
   43 |             rotate({i}, move);
      |             ~~~~~~^~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:1390:5: note: candidate: 'template<class _FIter> constexpr _FIter std::_V2::rotate(_FIter, _FIter, _FIter)'
 1390 |     rotate(_ForwardIterator __first, _ForwardIterator __middle,
      |     ^~~~~~
/usr/include/c++/13/bits/stl_algo.h:1390:5: note:   template argument deduction/substitution failed:
rotate.cpp:43:19: note:   candidate expects 3 arguments, 2 provided
   43 |             rotate({i}, move);
      |             ~~~~~~^~~~~~~~~~~
/usr/include/c++/13/pstl/glue_algorithm_defs.h:260:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::rotate(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _ForwardIterator)'
  260 | rotate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last);
      | ^~~~~~
/usr/include/c++/13/pstl/glue_algorithm_defs.h:260:1: note:   template argument deduction/substitution failed:
rotate.cpp:43:19: note:   candidate expects 4 arguments, 2 provided
   43 |             rotate({i}, move);
      |             ~~~~~~^~~~~~~~~~~