結果

問題 No.482 あなたの名は
ユーザー hotpepsihotpepsi
提出日時 2017-06-10 18:38:12
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 681 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 60,480 KB
実行使用メモリ 13,764 KB
最終ジャッジ日時 2024-09-24 15:45:04
合計ジャッジ時間 5,823 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 WA * 3 TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

class BIT {
	std::vector<int> bit;
	int size;
public:
	BIT() { }
	BIT(int sz) { init(sz); }
	void init(int sz) {
		bit = std::vector<int>((size = sz) + 1);
	}
	int sum(int i) {
		int s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	void add(int i, int x) {
		while (i <= size) {
			bit[i] += x;
			i += i & -i;
		}
	}
};

int main(int argc, char *argv[]) {
	int n, k, c = 0;
	cin >> n >> k;
	BIT b(200001);
	for (int i = 0; i < n; ++i) {
		int d;
		cin >> d;
		c += i - b.sum(d);
		b.add(d, 1);
	}
	bool ans = c <= k && ((k - c) % 2) == 0;
	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}
0