結果
問題 | No.2382 Amidakuji M |
ユーザー |
![]() |
提出日時 | 2023-07-14 21:39:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 121 ms / 2,000 ms |
コード長 | 1,482 bytes |
コンパイル時間 | 1,613 ms |
コンパイル使用メモリ | 200,076 KB |
最終ジャッジ日時 | 2025-02-15 13:47:10 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
コンパイルメッセージ
In file included from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from main.cpp:1: In static member function ‘static _Up* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = const int; _Up = int; bool _IsMove = false]’, inlined from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = const int*; _OI = int*]’ at /usr/include/c++/13/bits/stl_algobase.h:506:30, inlined from ‘_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = const int*; _OI = int*]’ at /usr/include/c++/13/bits/stl_algobase.h:533:42, inlined from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<const int*, vector<int> >; _OI = int*]’ at /usr/include/c++/13/bits/stl_algobase.h:540:31, inlined from ‘_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<const int*, vector<int> >; _OI = int*]’ at /usr/include/c++/13/bits/stl_algobase.h:633:7, inlined from ‘static _ForwardIterator std::__uninitialized_copy<true>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int> >; _ForwardIterator = int*]’ at /usr/include/c++/13/bits/stl_uninitialized.h:147:27, inlined from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const int*, vector<int> >; _ForwardIterator = int*]’ at /usr/include/c++/13/bits/stl_uninitialized.h:185:15, inlined from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const int*, vector<int> >; _ForwardIterator = int*; _Tp = int]’ at /usr/include/c++/13/bits/stl_uninitialized.h:373:37, inlined
ソースコード
#include <bits/stdc++.h>using namespace std;#ifdef LOCAL#include "settings/debug.cpp"#define _GLIBCXX_DEBUG#else#define Debug(...) void(0)#endifusing ll = long long;#define rep(i, n) for (int i = 0; i < (n); ++i)// Usage: T = 転倒数の型、U = 要素の型template<typename T, typename U>pair<T, vector<U>> invNum(vector<U> a) {size_t n = a.size();if (n <= 1) return { (T) 0, a };size_t mid = n / 2;auto left = invNum<T, U>(vector<U>(a.begin(), a.begin() + mid));auto right = invNum<T, U>(vector<U>(a.begin() + mid, a.end()));vector<U> res;T inv = 0;inv += left.first + right.first;size_t i = 0, j = 0;while (i < left.second.size() && j < right.second.size()) {if (left.second[i] <= right.second[j]) {res.push_back(left.second[i]);i++;}else {res.push_back(right.second[j]);j++;inv += left.second.size() - i;}}while (i < left.second.size()) {res.push_back(left.second[i]);i++;}while (j < right.second.size()) {res.push_back(right.second[j]);j++;}return { inv, res };}int main() {int n;ll m;cin >> n >> m;vector<int> p(n);rep(i, n) cin >> p[i];auto [inv, q] = invNum<ll, int>(p);Debug(inv);ll minim = (inv + m - 1) / m * m;if (minim % 2 == inv % 2) {cout << minim << endl;}else if ((minim + m) % 2 == inv % 2) {cout << minim + m << endl;}else {cout << -1 << endl;}return 0;}