結果

問題 No.482 あなたの名は
ユーザー fiord
提出日時 2017-02-27 21:10:42
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 516 bytes
コンパイル時間 585 ms
コンパイル使用メモリ 73,024 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-11 19:50:18
合計ジャッジ時間 2,293 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
	ll n, k;	cin >> n >> k;
	vector<int> a(n), pos(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];	a[i]--;
		pos[a[i]] = i;
	}
	ll need = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] != i) {
			need++;
			swap(a[i], a[pos[i]]);
			swap(pos[a[i]], pos[a[pos[i]]]);
		}
	}
	if (need > k)	cout << "NO" << endl;
	else if ((k - need) % 2 == 0)	cout << "YES" << endl;
	else	cout << "NO" << endl;
	return 0;
}
0