結果

問題 No.482 あなたの名は
ユーザー GB
提出日時 2018-11-15 23:36:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 884 bytes
コンパイル時間 602 ms
コンパイル使用メモリ 62,824 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-24 14:06:42
合計ジャッジ時間 2,770 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>

using namespace std;

int main() {

	int n = 0;
	long k = 0;
	vector<int> d;

	cin >> n>>k;
	long buff = k;
	d.resize(n,0);
	for (int i = 0;i < n;i++) {
		cin >> d[i];
	}

	int j = 0;
	while (j!=n-1) {
		if (d[j] != j+1) {
			int tmp = 0;
			tmp = d[j];
			d[j] = d[tmp - 1];
			d[tmp - 1] = tmp;
			k--;
		}
		else {
			j++;
		}
		if (k < 0)break;
	}

	if (k == 0)cout << "YES" << endl;
	else if (k < 0)cout << "NO" << endl;
	else if (k > 0) {
		long x = buff - k;
		if (x == 0) {
			if (buff % 2 == 0) {
				cout << "YES" << endl;
			}
			else {
				cout << "NO" << endl;
			}
		}
		else if(x%2!=0) {
			if (buff % 2 != 0) {
				cout << "YES" << endl;
			}
			else {
				cout << "NO" << endl;
			}
		}
		else if (x % 2 == 0) {
			if (buff % 2 == 0) {
				cout << "YES" << endl;
			}
			else {
				cout << "NO" << endl;
			}
		}
	}


	return 0;
}
0