結果

問題 No.482 あなたの名は
ユーザー misora192misora192
提出日時 2020-08-07 09:20:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,246 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 169,052 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 00:33:35
合計ジャッジ時間 3,588 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 21 ms
4,348 KB
testcase_16 AC 21 ms
4,348 KB
testcase_17 AC 22 ms
4,348 KB
testcase_18 AC 21 ms
4,348 KB
testcase_19 AC 21 ms
4,348 KB
testcase_20 AC 21 ms
4,348 KB
testcase_21 AC 21 ms
4,348 KB
testcase_22 AC 22 ms
4,348 KB
testcase_23 AC 21 ms
4,348 KB
testcase_24 AC 21 ms
4,348 KB
testcase_25 AC 21 ms
4,348 KB
testcase_26 AC 21 ms
4,348 KB
testcase_27 AC 22 ms
4,348 KB
testcase_28 AC 22 ms
4,348 KB
testcase_29 AC 20 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// class
const int max_n  = 202020;

class BinaryIndexedTree{

private:
	int n;
	ll bit[max_n];

public:
	BinaryIndexedTree(int n){
		this -> n = n;
	}

    ll sum(int i){
        ll s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & (-i);
        }
        return s;
    }

    void add(int i, ll x){
        while(i <= n){
            bit[i] += x;
            i += i & (-i);
        }
    }
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n, k;
	cin >> n >> k;

	vector<int> a(n);
	rep(i, n) cin >> a[i];

	BinaryIndexedTree bit(n);
	ll ans = 0ll;
	for(ll i = 0; i < n; i++){
		ans += i - bit.sum(a[i]);
		bit.add(a[i], 1ll);
	}

	ll ans2 = 0;
	rep(i, n){
		while(a[i] != i+1){
			int t = a[i];
			swap(a[i], a[t-1]);
			ans2++;
		}
	}

	// cout << ans << "," << ans2 << endl;

	if(ans2 <= k && (ans2 % 2 == k % 2)){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

}
0