結果

問題 No.2382 Amidakuji M
ユーザー t98slidert98slider
提出日時 2023-07-15 15:40:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 543 bytes
コンパイル時間 3,656 ms
コンパイル使用メモリ 230,184 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-17 02:03:24
合計ジャッジ時間 4,978 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 13 ms
4,368 KB
testcase_04 AC 22 ms
4,368 KB
testcase_05 AC 5 ms
4,368 KB
testcase_06 AC 14 ms
4,368 KB
testcase_07 AC 9 ms
4,368 KB
testcase_08 AC 3 ms
4,368 KB
testcase_09 AC 19 ms
4,368 KB
testcase_10 AC 28 ms
4,368 KB
testcase_11 AC 10 ms
4,368 KB
testcase_12 AC 19 ms
4,368 KB
testcase_13 AC 2 ms
4,368 KB
testcase_14 AC 2 ms
4,368 KB
testcase_15 AC 2 ms
4,368 KB
testcase_16 AC 2 ms
4,368 KB
testcase_17 AC 2 ms
4,368 KB
testcase_18 AC 1 ms
4,368 KB
testcase_19 AC 29 ms
4,368 KB
testcase_20 AC 30 ms
4,368 KB
testcase_21 AC 29 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll m, cnt = 0, cnt2;
    int n, v;
    cin >> n >> m;
    atcoder::fenwick_tree<int> fw(n);
    for(int i = 0; i < n; i++){
        cin >> v;
        cnt += fw.sum(v--, n);
        fw.add(v, 1);
    }
    cnt2 = (cnt + m - 1) / m * m;
    if((cnt2 - cnt) % 2 == 0){
        cout << cnt2 << '\n';
        return 0;
    }
    cnt2 += m;
    cout << (cnt2 - cnt & 1 ? -1 : cnt2) << '\n';
}
0