結果

問題 No.2382 Amidakuji M
ユーザー daiotadaiota
提出日時 2023-07-14 23:06:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 664 bytes
コンパイル時間 1,494 ms
コンパイル使用メモリ 164,324 KB
実行使用メモリ 6,740 KB
最終ジャッジ日時 2023-10-14 13:31:16
合計ジャッジ時間 2,850 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 13 ms
4,812 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 12 ms
4,896 KB
testcase_07 AC 8 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 16 ms
5,652 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,356 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 WA -
testcase_19 AC 29 ms
6,548 KB
testcase_20 AC 26 ms
6,740 KB
testcase_21 AC 26 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i=0;i<int(n);i++)

ll N;
ll bit[200010],v[200010];

// 1-indexed
// v[a]+=w


void add(ll a,ll w){
 for(ll x=a;x<=N;x+=x&-x) bit[x]+=w;
}


// v[1]+...+v[a]


int sum(int a){
 int ret=0;
 for (int x=a;x>0;x-=x&-x) ret+=bit[x];
 return ret;
}


int main(void){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
	ll i,j,k;

	ll M;
	cin >> N >> M;

	ll a=0;
	for(i=0;i<N;i++) cin >> v[i];

	for(i=0;i<N;i++){
		a+=i-sum(v[i]);
		add(v[i],1);
	}

	ll K=(a+M-1)/M;
	if((M*K-a)%2==0) cout << M*K << endl;
	else cout << -1 << endl;


	return 0;
}
0