結果
問題 | No.2382 Amidakuji M |
ユーザー |
|
提出日時 | 2023-07-15 15:40:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 543 bytes |
コンパイル時間 | 4,267 ms |
コンパイル使用メモリ | 229,008 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-17 00:37:24 |
合計ジャッジ時間 | 5,682 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#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';}