結果
| 問題 | No.482 あなたの名は |
| コンテスト | |
| ユーザー |
tsutaj
|
| 提出日時 | 2019-01-16 21:14:21 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 2,000 ms |
| コード長 | 530 bytes |
| 記録 | |
| コンパイル時間 | 516 ms |
| コンパイル使用メモリ | 79,612 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2026-03-17 15:55:02 |
| 合計ジャッジ時間 | 2,080 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long int N, K; cin >> N >> K;
vector<int> p(N), used(N);
for(int i=0; i<N; i++) {
cin >> p[i]; p[i]--;
}
long long int sum = 0;
for(int i=0; i<N; i++) {
int cnt = 0, idx = i;
for(; used[idx] == false; idx = p[idx]) used[idx] = true, cnt++;
if(cnt > 0) sum += cnt - 1;
}
if(sum <= K and K % 2 == sum % 2) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
tsutaj