結果

問題 No.482 あなたの名は
ユーザー umaumaxumaumax
提出日時 2017-05-08 07:53:55
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 664 bytes
コンパイル時間 2,249 ms
コンパイル使用メモリ 70,960 KB
実行使用メモリ 20,956 KB
最終ジャッジ日時 2023-10-12 17:34:47
合計ジャッジ時間 6,545 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

int main(int argc, const char* argv[])
{
	int N;
	int64_t K;
	cin >> N >> K;
	int D[N];
	for (auto&& d : D) cin >> d;

	//	NOTE 循環するグループに分ける
	map<int, int> m;
	map<int, int> gm;
	int g = 1;
	for (int i = 1; i <= N; i++) {
		int d  = D[i - 1];
		int _g = m[i] ? m[i] : (m[d] ? m[d] : g++);
		gm[_g]++;
		m[i] = _g;
		m[d] = _g;
	}

	int64_t cnt = 0;
	for (auto&& tmp : gm) {
		cnt += max(tmp.second - 1, 0);
	}
	//	NOTE 2,3回の倍数の交換は組み合わせで可能
	bool ret = cnt == K || cnt + 2 <= K;
	cout << (ret ? "YES" : "NO") << endl;
	return 0;
}
0