結果
問題 |
No.482 あなたの名は
|
ユーザー |
|
提出日時 | 2019-10-25 19:21:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 554 bytes |
コンパイル時間 | 620 ms |
コンパイル使用メモリ | 64,444 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-21 16:20:21 |
合計ジャッジ時間 | 2,736 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <iostream> using namespace std; using ll = long long; ll N, K, D[200020]; bool used[200020]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> N >> K; for(int i = 1; i <= N; ++i) cin >> D[i]; ll ans = 0; for(int i = 1; i <= N; ++i) { if(!used[i] && i != D[i]) { used[i] = true; int pos = D[i]; while(pos != i) { used[pos] = true; pos = D[pos]; ++ans; } } } if(ans <= K && ans % 2 == K % 2) cout << "YES"; else cout << "NO"; cout << '\n'; return 0; }