結果

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

ソースコード

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]]);
		}
	}
	if (need > k)	cout << "NO" << endl;
	else if ((k - need) % 2 == 0)	cout << "YES" << endl;
	else	cout << "NO" << endl;
	return 0;
}
0